473,327 Members | 2,025 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,327 software developers and data experts.

Function that convert Hexadecimal to Binary?

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 43503
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" <Mr*****@discussions.microsoft.com> 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
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==?="
<Mr*****@discussions.microsoft.com> 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
* "=?Utf-8?B?TXJLcmljaA==?=" <Mr*****@discussions.microsoft.com> 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]
<URL:http://dotnet.mvps.org/>
<URL:http://dotnet.mvps.org/dotnet/faqs/>
Nov 20 '05 #4
Jason, try this shortcut

TextBox2.Text=Convert.ToString(from, 2)

"Jason L James" <ja***@no-spam.dive-master.org> 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==?="
<Mr*****@discussions.microsoft.com> 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 #5
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" <ja***@no-spam.dive-master.org> 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==?="
<Mr*****@discussions.microsoft.com> 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
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]"
<Ja************@msn.com> 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 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" <ja***@no-spam.dive-master.org> 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==?="
<Mr*****@discussions.microsoft.com> 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 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Eric | last post by:
Guys, I have the following hexadecimal string - '\xff\xff\xff' which i need to convert to binary. How would i go about doing this? Eric
7
by: Golan | last post by:
Hi, I need to convert a Binary value to Decimal. I've been told that the value is an unsigned one. How can I do this? I use memcpy into an unsigned char variable, but when I print the value I got...
29
by: Harlin Seritt | last post by:
Hi... I would like to take a string like 'supercalifragilisticexpialidocius' and write it to a file in binary forms -- this way a user cannot read the string in case they were try to open in...
1
by: svnlakshmi | last post by:
Pls help me out in this aspect--How to convert a binary file to a file in text format using C?
1
by: pnbaocuong | last post by:
Dear All When I try to use convert function of MS sql server like this: String sql = " (employee_id = '" + employee_id + "') and ((convert(VARCHAR,w_date,103) = '" + w_date + "'))"; ...
8
by: sivadhanekula | last post by:
Hi everyone... I have a data with both decimal and Hexadecimal numbers. I am extracting the required data from for analysis with the help of MINITAB 15. The problem is MINITAB 15 is not accepting...
0
by: jcarter | last post by:
How can I create a CodeDOM statement to accomplish the following this.pictureBox.Image = <Convert the binary value of the picture from the XML file and display> I have tried the following...
6
by: ikbel borcheni | last post by:
How to convert an hexadecimal integer to decimal integer? Is there a function to do that in VC++?
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.