Jonathan Crispe

Jonathan Crispe

  • NA
  • 46
  • 48.4k

How to use binary operation

Oct 21 2011 1:52 AM
I was able to convert Hex values to binary,
but i can't figure out how to calculate the 2 16bit-binary value: An example shown below.


  public partial class Form1 : Form
  {
  uint byhex1 = 0;
  uint byhex2 = 0;

  public Form1()
  {
  InitializeComponent();
 
  }
  private void Form1_Load(object sender, EventArgs e)
  {

  }
  private void BTN_operation_Click(object sender, EventArgs e)
  {
  if (RB_andgate.Checked)
  {
  BTN_operation.Text = "&";
  byhex1 = Convert.ToUInt16(TXB_hexvalue1.Text, 16);
  LBL_binary1.Text = Convert.ToString(byhex1, 2).PadLeft(16, '0');
  byhex2 = Convert.ToUInt16(TXB_hexvalue2.Text, 16);
  LBL_binary2.Text = Convert.ToString(byhex2, 2).PadLeft(16, '0');
  LBL_totalhex.Text = "0 X " + (byhex1 & byhex2).ToString("X4");
  }
  if (RB_orgate.Checked)
  {
  BTN_operation.Text = "|";
  byhex1 = Convert.ToUInt32(TXB_hexvalue1.Text, 16);
  LBL_binary1.Text = Convert.ToString(byhex1, 2).PadLeft(16, '0');
  byhex2 = Convert.ToUInt32(TXB_hexvalue2.Text, 16);
  LBL_binary2.Text = Convert.ToString(byhex2, 2).PadLeft(16, '0');
  LBL_totalhex.Text = "0 X " + (byhex1 | byhex2).ToString("X4");
  }
  if (RB_xorgate.Checked)
  {
  BTN_operation.Text = "^";
  byhex1 = Convert.ToUInt32(TXB_hexvalue1.Text, 16);
  LBL_binary1.Text = Convert.ToString(byhex1, 2).PadLeft(16, '0');
  byhex2 = Convert.ToUInt32(TXB_hexvalue2.Text, 16);
  LBL_binary2.Text = Convert.ToString(byhex2, 2).PadLeft(16, '0');
  LBL_totalhex.Text = "0 X " + (byhex1 ^ byhex2).ToString("X4");
  }
  }
  }
how to put an exception just like in picture below in my code?



Answers (2)