Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Windows;
- namespace intToBinary
- {
- /// <summary>
- /// Created by AnorexicSeal
- /// convert integer to binary and to hexadecimal
- /// </summary>
- public partial class MainWindow : Window
- {
- public MainWindow()
- {
- InitializeComponent();
- }
- private string value, result;
- private int x;
- private bool binaryBox, hexBox;
- private void /*rename to your button action*/(object sender, RoutedEventArgs e)
- {
- // rename integerBox to your box or leave it as it is and just name it like that
- try
- {
- binaryBox = binaryCheckBox.IsChecked == true;
- hexBox = hexadecimalCheckBox.IsChecked == true;
- result = Convert.ToString(x,2);
- x = int.Parse(integerBox.Text);
- value = x.ToString("X8");
- if (binaryBox == true )
- {
- //converts said integert into binary format
- resultLabel.Text = $"Binary:{result}";
- }
- if (hexBox == true )
- {
- //converts from integer to hexadecimal
- resultLabel.Text = $"Hex:{value}";
- }
- if (binaryBox == true && hexBox == true)
- {
- // just in case the user decides to click on both
- resultLabel.Text = $"Binary:{result}\nHex:{value}";
- }
- if (binaryBox == false && hexBox == false)
- {
- // if nothing is selected
- resultLabel.Text = string.Empty;
- }
- }
- catch (Exception )
- {
- resultLabel.Text = " Value is too large or nothing at all";
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement