473,396 Members | 1,757 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,396 software developers and data experts.

Converting String to Hex

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
6 43122
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
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
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
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Hal Vaughan | last post by:
If I have a byte and I convert it to string (String sData = new String(byte bData), then convert it back (byte bData = sData.getBytes()), will all data be intact, or do Strings have problems with...
2
by: Jonas Prismesen | last post by:
Hi! I have string like this: string expr = "123/(12*3)"; And I want to actually calculate the mathematical expression in the string. Is there an easy way do it? Or do I have to extract all...
13
by: Gil | last post by:
I have a string : string A = "2"; I need to get it's integer value : // ?? int val = A ; // ??
7
by: AlexFarokhyans | last post by:
Hello, I'm trying to convert String to Char array. I'm getting a string from user input text box and then I have char firstName. I need to convert the string that is in the text box to firstName....
4
by: rainmaker1234 | last post by:
Its very simple in VC++. In the followeing code I have declared a String, and a double than I am taking the string and converting it into Double. getch() at the end is only to pause the screen so...
1
by: Sandra | last post by:
I am trying to convert a string into a uniqueidentifier by using the following code string contrID = Request.Params["oId" SqlGuid sqlID = SqlGuid.Parse(contrID I am then putting sqlID into my...
1
by: mdawoodk | last post by:
i am getting error "input string was not in correct format" when converting a string decimal into integer value. code is like this: string strVal = ""; int nVal = 0; strVal = "14.9"; nVal...
5
by: SMichal | last post by:
Hi, how can I parse string "? 20.000" to double ?
3
by: coconet | last post by:
I have a string like this mystring = "color1:blue;color2:red"; I am tring to convert this into an IDictionary populated like this: color1 blue color2 red My non-working syntax is
3
by: kronus | last post by:
I'm receiving an xml file that has a child called modified and it represents a date value in the form of a string -- Nov 14, 2008 -- and in my app, I have items associated with each object and I'm...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
0
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...
0
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,...
0
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...

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.