Advertisement
Guest User

Untitled

a guest
Jul 28th, 2016
57
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.90 KB | None | 0 0
  1. using System;
  2. using System.Windows;
  3.  
  4. namespace intToBinary
  5. {
  6. /// <summary>
  7. /// Created by AnorexicSeal
  8. /// convert integer to binary and to hexadecimal
  9. /// </summary>
  10. public partial class MainWindow : Window
  11. {
  12. public MainWindow()
  13. {
  14. InitializeComponent();
  15.  
  16. }
  17.  
  18. private string value, result;
  19. private int x;
  20. private bool binaryBox, hexBox;
  21.  
  22. private void /*rename to your button action*/(object sender, RoutedEventArgs e)
  23. {
  24. // rename integerBox to your box or leave it as it is and just name it like that
  25.  
  26. try
  27. {
  28. binaryBox = binaryCheckBox.IsChecked == true;
  29. hexBox = hexadecimalCheckBox.IsChecked == true;
  30.  
  31. result = Convert.ToString(x,2);
  32. x = int.Parse(integerBox.Text);
  33. value = x.ToString("X8");
  34.  
  35.  
  36.  
  37. if (binaryBox == true )
  38. {
  39. //converts said integert into binary format
  40.  
  41. resultLabel.Text = $"Binary:{result}";
  42. }
  43. if (hexBox == true )
  44. {
  45. //converts from integer to hexadecimal
  46.  
  47. resultLabel.Text = $"Hex:{value}";
  48.  
  49. }
  50. if (binaryBox == true && hexBox == true)
  51. {
  52. // just in case the user decides to click on both
  53.  
  54. resultLabel.Text = $"Binary:{result}\nHex:{value}";
  55.  
  56. }
  57. if (binaryBox == false && hexBox == false)
  58. {
  59. // if nothing is selected
  60.  
  61. resultLabel.Text = string.Empty;
  62. }
  63. }
  64. catch (Exception )
  65. {
  66. resultLabel.Text = " Value is too large or nothing at all";
  67.  
  68. }
  69.  
  70. }
  71. }
  72. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement