473,593 Members | 2,813 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 43600
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" <Mr*****@discus sions.microsoft .com> wrote in message
news:E0******** *************** ***********@mic rosoft.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(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= =?="
<Mr*****@discus sions.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*****@discus sions.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=C onvert.ToString (from, 2)

"Jason L James" <ja***@no-spam.dive-master.org> wrote in message
news:40******** *******@news.ne wnet.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(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= =?="
<Mr*****@discus sions.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.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:
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.ne wnet.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(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= =?="
<Mr*****@discus sions.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.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:
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.n ewnet.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(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= =?="
<Mr*****@discus sions.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
6578
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
13067
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 a negative value. For example if I'm using the xd -c (Unix) on the file, I can see the value FFFFFFFFFFFFFFA2 which using the memcpy as described above I get -94. But the real value that I'd expect to get is a positive one.
29
5067
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 something like ascii text editor. I'd also like to be able to read the binary formed data back into string format so that it shows the original value. Is there any way to do this in Python? Thanks!
1
2275
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
6070
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 + "'))"; PAYROLLDataSet.WORKINGTIMESRow workingtime_row = (PAYROLLDataSet.WORKINGTIMESRow)pAYROLLDataSet.WORKINGTIMES.Select(sql); Whe I run, it rais bellow exception:
8
9956
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 the Hexdec data, so while extracting itself I need to convert the data from Hex to decimal. For extracting the data I am using Visual Studios "VC++" can anyone help me how to do the conversion. Thanks in advance Regards Siva
0
1533
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 without any success...... MemoryStream ms = new MemoryStream(Convert.FromBase64String((String)ControlPropertyTable));
6
3522
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
7936
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
7874
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8241
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8366
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
7997
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
1
5738
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5402
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
3893
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1203
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.