444,168 Members | 2,599 Online Need help? Post your question and get tips & solutions from a community of 444,168 IT Pros & Developers. It's quick & easy.

# Function that convert Hexadecimal to Binary?

 P: n/a I want to convert Hexadecimal or normal integer to Binary. Does VB.Net has function to do that? I only found Hex function that convert normal integer to Hexadecimal. Nov 20 '05 #1
6 Replies

 P: n/a MrKrich, You can use Convert.ToInt32 to go from a string to an integer. You can use Convert.ToString to go from a integer to a String. Both support both Hex & Binary, as well as octal & decimal (2, 8, 10, or 16 from base) Dim s As String = "fab4" Dim i As Integer = Convert.ToInt32(s, 16) Dim s2 As String = Convert.ToString(i, 2) Dim i2 As Integer = Convert.ToInt32(s2, 2) Hope this helps Jay "MrKrich" wrote in message news:E0**********************************@microsof t.com... I want to convert Hexadecimal or normal integer to Binary. Does VB.Net has function to do that? I only found Hex function that convert normal integer to Hexadecimal. Nov 20 '05 #2

 P: n/a Try is code. Is takes the text from TextBox1 and converts it into a string of 1's and 0's that represent the binary code of the number. Dim from As Int32 If IsNumeric(TextBox1.Text) Then from = TextBox1.Text Dim n As Int16 Do n = from Mod 2 TextBox2.Text = n & TextBox2.Text from \= 2 Loop Until from = 0 End If Hope this helps. Jason. On Sun, 18 Jul 2004 08:21:06 -0700, "=?Utf-8?B?TXJLcmljaA==?=" wrote: I want to convert Hexadecimal or normal integer to Binary. Does VB.Net has function to do that? I only found Hex function that convert normal integer to Hexadecimal. Nov 20 '05 #3

 P: n/a * "=?Utf-8?B?TXJLcmljaA==?=" scripsit: I want to convert Hexadecimal or normal integer to Binary. Does VB.Net has function to do that? I only found Hex function that convert normal integer to Hexadecimal. In addition to Jay's reply, you can use 'Val' to parse a string containing a number in hexadecimal format. -- Herfried K. Wagner [MVP] Nov 20 '05 #4

 P: n/a Jason, try this shortcut TextBox2.Text=Convert.ToString(from, 2) "Jason L James" wrote in message news:40***************@news.newnet.co.uk... Try is code. Is takes the text from TextBox1 and converts it into a string of 1's and 0's that represent the binary code of the number. Dim from As Int32 If IsNumeric(TextBox1.Text) Then from = TextBox1.Text Dim n As Int16 Do n = from Mod 2 TextBox2.Text = n & TextBox2.Text from \= 2 Loop Until from = 0 End If Hope this helps. Jason. On Sun, 18 Jul 2004 08:21:06 -0700, "=?Utf-8?B?TXJLcmljaA==?=" wrote:I want to convert Hexadecimal or normal integer to Binary. Does VB.Net hasfunction to do that? I only found Hex function that convert normal integerto Hexadecimal. Nov 20 '05 #5

 P: n/a Jason, In addition to trying Convert.ToString as Greg and I suggested. Consider using <<= or >>= instead of *= & \= by 2. In VS.NET << is the left shift operator, while >> is the right shift operator So: from \= 2 from >>= 1 Are both the same, while the second may be faster, as bit shifting is normally faster then division. Hope this helps Jay "Jason L James" wrote in message news:40***************@news.newnet.co.uk... Try is code. Is takes the text from TextBox1 and converts it into a string of 1's and 0's that represent the binary code of the number. Dim from As Int32 If IsNumeric(TextBox1.Text) Then from = TextBox1.Text Dim n As Int16 Do n = from Mod 2 TextBox2.Text = n & TextBox2.Text from \= 2 Loop Until from = 0 End If Hope this helps. Jason. On Sun, 18 Jul 2004 08:21:06 -0700, "=?Utf-8?B?TXJLcmljaA==?=" wrote:I want to convert Hexadecimal or normal integer to Binary. Does VB.Net has function to do that? I only found Hex function that convert normal integer to Hexadecimal. Nov 20 '05 #6

 P: n/a Jay/Greg, Thanks for the feedback. I have been using variations of the routine I submitted in VB6 and C for a long time. Your improvements will help the speed and readability of my code considerably. The string.convert method has a huge number of possibilities in my VB.Net code. Regards, Jason. On Sun, 18 Jul 2004 11:59:05 -0500, "Jay B. Harlow [MVP - Outlook]" wrote: Jason,In addition to trying Convert.ToString as Greg and I suggested.Consider using <<= or >>= instead of *= & \= by 2.In VS.NET << is the left shift operator, while >> is the right shiftoperatorSo: from \= 2 from >>= 1Are both the same, while the second may be faster, as bit shifting isnormally faster then division.Hope this helpsJay "Jason L James" wrote in messagenews:40***************@news.newnet.co.uk... Try is code. Is takes the text from TextBox1 and converts it into a string of 1's and 0's that represent the binary code of the number. Dim from As Int32 If IsNumeric(TextBox1.Text) Then from = TextBox1.Text Dim n As Int16 Do n = from Mod 2 TextBox2.Text = n & TextBox2.Text from \= 2 Loop Until from = 0 End If Hope this helps. Jason. On Sun, 18 Jul 2004 08:21:06 -0700, "=?Utf-8?B?TXJLcmljaA==?=" wrote: >I want to convert Hexadecimal or normal integer to Binary. Does VB.Nethas function to do that? I only found Hex function that convert normalinteger to Hexadecimal. Nov 20 '05 #7

### This discussion thread is closed

Replies have been disabled for this discussion. 