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.
Function that convert Hexadecimal to Binary?
Collapse
This topic is closed.
X
X
-
MrKrichTags: None -
Jay B. Harlow [MVP - Outlook]
Re: Function that convert Hexadecimal to Binary?
MrKrich,
You can use Convert.ToInt32 to go from a string to an integer.
You can use Convert.ToStrin g 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.ToStrin g(i, 2)
Dim i2 As Integer = Convert.ToInt32 (s2, 2)
Hope this helps
Jay
"MrKrich" <MrKrich@discus sions.microsoft .com> wrote in message
news:E0370128-A6D5-43F7-894D-7B90D07D474D@mi crosoft.com...[color=blue]
> I want to convert Hexadecimal or normal integer to Binary. Does VB.Net has[/color]
function to do that? I only found Hex function that convert normal integer
to Hexadecimal.
-
Jason L James
Re: Function that convert Hexadecimal to Binary?
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(TextB ox1.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= =?="
<MrKrich@discus sions.microsoft .com> wrote:
[color=blue]
>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.[/color]
Comment
-
Herfried K. Wagner [MVP]
Re: Function that convert Hexadecimal to Binary?
* "=?Utf-8?B?TXJLcmljaA= =?=" <MrKrich@discus sions.microsoft .com> scripsit:[color=blue]
> 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.[/color]
In addition to Jay's reply, you can use 'Val' to parse a string
containing a number in hexadecimal format.
--
Herfried K. Wagner [MVP]
<URL:http://dotnet.mvps.org/>
<URL:http://dotnet.mvps.org/dotnet/faqs/>
Comment
-
Greg Burns
Re: Function that convert Hexadecimal to Binary?
Jason, try this shortcut
TextBox2.Text=C onvert.ToString (from, 2)
"Jason L James" <jason@no-spam.dive-master.org> wrote in message
news:40fa9f8e.2 3710383@news.ne wnet.co.uk...[color=blue]
> 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(TextB ox1.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= =?="
> <MrKrich@discus sions.microsoft .com> wrote:
>[color=green]
>>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.[/color]
>[/color]
Comment
-
Jay B. Harlow [MVP - Outlook]
Re: Function that convert Hexadecimal to Binary?
Jason,
In addition to trying Convert.ToStrin g 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:[color=blue]
> from \= 2[/color]
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" <jason@no-spam.dive-master.org> wrote in message
news:40fa9f8e.2 3710383@news.ne wnet.co.uk...[color=blue]
> 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(TextB ox1.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= =?="
> <MrKrich@discus sions.microsoft .com> wrote:
>[color=green]
> >I want to convert Hexadecimal or normal integer to Binary. Does VB.Net[/color][/color]
has function to do that? I only found Hex function that convert normal
integer to Hexadecimal.[color=blue]
>[/color]
Comment
-
Jason L James
Re: Function that convert Hexadecimal to Binary?
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]"
<Jay_Harlow_MVP @msn.com> wrote:
[color=blue]
>Jason,
>In addition to trying Convert.ToStrin g 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:[color=green]
>> from \= 2[/color]
> 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" <jason@no-spam.dive-master.org> wrote in message
>news:40fa9f8e. 23710383@news.n ewnet.co.uk...[color=green]
>> 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(TextB ox1.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= =?="
>> <MrKrich@discus sions.microsoft .com> wrote:
>>[color=darkred]
>> >I want to convert Hexadecimal or normal integer to Binary. Does VB.Net[/color][/color]
>has function to do that? I only found Hex function that convert normal
>integer to Hexadecimal.[color=green]
>>[/color]
>
>[/color]
Comment
Comment