473,757 Members | 8,085 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 43660
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
6591
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
13085
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
5087
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
2297
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
6088
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
9966
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
1560
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
3528
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
9298
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
10072
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
9906
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...
0
9737
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8737
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6562
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
5172
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
3829
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
3399
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.