Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C#
Hi All,
 
Battling away I need to display a binary from a string "4020",
I have used the method
            MessageBox.Show(Returned);
            Hexvalue2 = Convert.ToUInt32(Returned, 16);
            MessageBox.Show(Hexvalue2.ToString());
to convert my string to a form that can be used that with
 
            if ((Hexvalue2 & 0x0001) == 0)
            {
                //MessageBox.Show("hello bit 1 not set");
                checkBox1.Checked = false;
                label9.Text = "False";
                }
            else
            {
               // MessageBox.Show("bit 1 set");
                checkBox1.Checked = true;
                label9.Text = "True"; 
            
            }
to check if bits are set and update a string accordingly This appears to working fine but bits 4 & 32 seem to inverted I was hoping for a look at the binary data before yelling fowl to higher ups! So I did the following
            Hexvalue2 = Convert.ToUInt32(IU_status,2);
            textBox2.Text = Hexvalue2.ToString();
and get an Could not find any recognizable digits error. Is the correct way of doing what I'm after or have I been seduced by Convert.To again?
 
Glenn
Posted 15-Jan-13 2:06am

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

You are taking an input from the TextBox and wanted to convert it into binary or hexadecimal number.
 
Since you take input from the TextBox you have its datatype is String and you have to convert that String into int, long, etc Depending upon your requirement.
 
To convert your number to Hexadecimal Number refer to Hex Converter[^]
 
bcoz when you convert string to any numerical form like int, long, float, etc it is in the decimal number only
 
To convert your Number to any Base like Binary, octal, etc refer to Conversion of Decimal to any Base (Binary, Octal or Hexa) and vice-versa (C#)[^]
  Permalink  
Comments
glennPattonWork at 15-Jan-13 9:26am
   
Didn't need to do it in the end

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 DamithSL 400
1 Maciej Los 222
2 OriginalGriff 213
3 Zoltán Zörgő 135
4 BillWoodruff 130
0 OriginalGriff 7,969
1 DamithSL 6,139
2 Sergey Alexandrovich Kryukov 5,449
3 Maciej Los 5,309
4 Kornfeld Eliyahu Peter 4,539


Advertise | Privacy | Mobile
Web04 | 2.8.141223.1 | Last Updated 15 Jan 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100