By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,723 Members | 1,298 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,723 IT Pros & Developers. It's quick & easy.

Converting String to Hex

P: n/a
LCD
This a rather simple question for all you studs out there! Please help me
with this. I have a string = "Please help me", and I want to convert this
into it's hex equivalent. How do I do it, I have trying for a couple hours
and can't seem to get my head straight arount this whole conversion things.

TIA, LCD
Nov 21 '05 #1
Share this Question
Share on Google+
6 Replies


P: n/a
Not sure exactly what you want to do but check out the Hex Function, Convert
Class, and ToCharArray string method. One or all of these in combination
should get you what you want.
--
Dennis in Houston
"LCD" wrote:
This a rather simple question for all you studs out there! Please help me
with this. I have a string = "Please help me", and I want to convert this
into it's hex equivalent. How do I do it, I have trying for a couple hours
and can't seem to get my head straight arount this whole conversion things.

TIA, LCD

Nov 21 '05 #2

P: n/a
LCD
Okay I want to doing something similar to this. In python, there is a
function called "binascii".

So if I type:
###
binascii.hexlify('hello world')

This is the result I get:

'68656c6c6f20776f726c64'
###

I want to do something similar in VB.NET or C#. Can someone help?

"Dennis" wrote:
Not sure exactly what you want to do but check out the Hex Function, Convert
Class, and ToCharArray string method. One or all of these in combination
should get you what you want.
--
Dennis in Houston
"LCD" wrote:
This a rather simple question for all you studs out there! Please help me
with this. I have a string = "Please help me", and I want to convert this
into it's hex equivalent. How do I do it, I have trying for a couple hours
and can't seem to get my head straight arount this whole conversion things.

TIA, LCD

Nov 21 '05 #3

P: n/a
Dim str As String = "hello world"
Dim byteArray() As Byte

byteArray = System.Text.ASCIIEncoding.ASCII.GetBytes(str)

"LCD" wrote:
Okay I want to doing something similar to this. In python, there is a
function called "binascii".

So if I type:
###
binascii.hexlify('hello world')


This is the result I get:

'68656c6c6f20776f726c64'
###

I want to do something similar in VB.NET or C#. Can someone help?

"Dennis" wrote:
Not sure exactly what you want to do but check out the Hex Function, Convert
Class, and ToCharArray string method. One or all of these in combination
should get you what you want.
--
Dennis in Houston
"LCD" wrote:
This a rather simple question for all you studs out there! Please help me
with this. I have a string = "Please help me", and I want to convert this
into it's hex equivalent. How do I do it, I have trying for a couple hours
and can't seem to get my head straight arount this whole conversion things.

TIA, LCD

Nov 21 '05 #4

P: n/a
I just realized you are probably asking for the ascii values of each
character of a string in hex format. This should do it for you:

Dim str As String = "hello world"
Dim byteArray() As Byte
Dim hexNumbers As System.Text.StringBuilder = New System.Text.StringBuilder

byteArray = System.Text.ASCIIEncoding.ASCII.GetBytes(str)

For i As Integer = 0 To byteArray.Length - 1
hexNumbers.Append(byteArray(i).ToString("x"))
Next

MessageBox.Show(hexNumbers.ToString())

The output should be:
68656c6c6f20776f726c64

"rmacias" wrote:
Dim str As String = "hello world"
Dim byteArray() As Byte

byteArray = System.Text.ASCIIEncoding.ASCII.GetBytes(str)

"LCD" wrote:
Okay I want to doing something similar to this. In python, there is a
function called "binascii".

So if I type:
###
>> binascii.hexlify('hello world')


This is the result I get:

'68656c6c6f20776f726c64'
###

I want to do something similar in VB.NET or C#. Can someone help?

"Dennis" wrote:
Not sure exactly what you want to do but check out the Hex Function, Convert
Class, and ToCharArray string method. One or all of these in combination
should get you what you want.
--
Dennis in Houston
"LCD" wrote:

> This a rather simple question for all you studs out there! Please help me
> with this. I have a string = "Please help me", and I want to convert this
> into it's hex equivalent. How do I do it, I have trying for a couple hours
> and can't seem to get my head straight arount this whole conversion things.
>
> TIA, LCD

Nov 21 '05 #5

P: n/a
LCD
Dude, you are genius!

You made it like POC (piece of cake). Now please explain me this, I didn't
quite catch this part:

hexNumbers.Append(byteArray(i).ToString("x"))

where is this "x" coming from? and why?

TIA, LCD

"rmacias" wrote:
I just realized you are probably asking for the ascii values of each
character of a string in hex format. This should do it for you:

Dim str As String = "hello world"
Dim byteArray() As Byte
Dim hexNumbers As System.Text.StringBuilder = New System.Text.StringBuilder

byteArray = System.Text.ASCIIEncoding.ASCII.GetBytes(str)

For i As Integer = 0 To byteArray.Length - 1
hexNumbers.Append(byteArray(i).ToString("x"))
Next

MessageBox.Show(hexNumbers.ToString())

The output should be:
68656c6c6f20776f726c64

"rmacias" wrote:
Dim str As String = "hello world"
Dim byteArray() As Byte

byteArray = System.Text.ASCIIEncoding.ASCII.GetBytes(str)

"LCD" wrote:
Okay I want to doing something similar to this. In python, there is a
function called "binascii".

So if I type:
###
>>> binascii.hexlify('hello world')

This is the result I get:

'68656c6c6f20776f726c64'
###

I want to do something similar in VB.NET or C#. Can someone help?

"Dennis" wrote:

> Not sure exactly what you want to do but check out the Hex Function, Convert
> Class, and ToCharArray string method. One or all of these in combination
> should get you what you want.
> --
> Dennis in Houston
>
>
> "LCD" wrote:
>
> > This a rather simple question for all you studs out there! Please help me
> > with this. I have a string = "Please help me", and I want to convert this
> > into it's hex equivalent. How do I do it, I have trying for a couple hours
> > and can't seem to get my head straight arount this whole conversion things.
> >
> > TIA, LCD

Nov 21 '05 #6

P: n/a
The Byte structure has several overloaded ToString() methods. The one used
below accepts a string representation of a NumberFormatInfo.

"X" or "x" means the format will be hexadecimal
"D" or "d" means the format will be in decimal, etc.

The below links shows possible formats:

http://msdn.microsoft.com/library/de...classtopic.asp
"LCD" wrote:
Dude, you are genius!

You made it like POC (piece of cake). Now please explain me this, I didn't
quite catch this part:

hexNumbers.Append(byteArray(i).ToString("x"))

where is this "x" coming from? and why?

TIA, LCD

"rmacias" wrote:
I just realized you are probably asking for the ascii values of each
character of a string in hex format. This should do it for you:

Dim str As String = "hello world"
Dim byteArray() As Byte
Dim hexNumbers As System.Text.StringBuilder = New System.Text.StringBuilder

byteArray = System.Text.ASCIIEncoding.ASCII.GetBytes(str)

For i As Integer = 0 To byteArray.Length - 1
hexNumbers.Append(byteArray(i).ToString("x"))
Next

MessageBox.Show(hexNumbers.ToString())

The output should be:
68656c6c6f20776f726c64

"rmacias" wrote:
Dim str As String = "hello world"
Dim byteArray() As Byte

byteArray = System.Text.ASCIIEncoding.ASCII.GetBytes(str)

"LCD" wrote:

> Okay I want to doing something similar to this. In python, there is a
> function called "binascii".
>
> So if I type:
> ###
> >>> binascii.hexlify('hello world')
>
> This is the result I get:
>
> '68656c6c6f20776f726c64'
> ###
>
> I want to do something similar in VB.NET or C#. Can someone help?
>
> "Dennis" wrote:
>
> > Not sure exactly what you want to do but check out the Hex Function, Convert
> > Class, and ToCharArray string method. One or all of these in combination
> > should get you what you want.
> > --
> > Dennis in Houston
> >
> >
> > "LCD" wrote:
> >
> > > This a rather simple question for all you studs out there! Please help me
> > > with this. I have a string = "Please help me", and I want to convert this
> > > into it's hex equivalent. How do I do it, I have trying for a couple hours
> > > and can't seem to get my head straight arount this whole conversion things.
> > >
> > > TIA, LCD

Nov 21 '05 #7

This discussion thread is closed

Replies have been disabled for this discussion.