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

BitConverter question

Hi,
I have a byte[] that i want to convert into a string. I use the
BitConverter.ToString() method.

Now, how do I convert that string back into a byte[]?

Thanks in advance,

Tim.
Nov 16 '05 #1
3 6373
Use Base64 instead. BitConverter.ToString(bytes) is just simple way to
formatted hex string from byte array.
byte[] myBytes = new byte[]{1,2,3};
string b64 = Convert.ToBase64String(myBytes);
Console.WriteLine(b64);
// Convert back to bytes.
byte[] myBytes2 = Convert.FromBase64String(b64);
Console.WriteLine("myBytes.Length:"+myBytes2.Lengt h);

--
William Stacey, MVP
http://mvp.support.microsoft.com

"Timothy V" <tr****@msn.com> wrote in message
news:ua**************@TK2MSFTNGP09.phx.gbl...
Hi,
I have a byte[] that i want to convert into a string. I use the
BitConverter.ToString() method.

Now, how do I convert that string back into a byte[]?

Thanks in advance,

Tim.


Nov 16 '05 #2
Use Base64 instead. BitConverter.ToString(bytes) is just simple way to
formatted hex string from byte array.
byte[] myBytes = new byte[]{1,2,3};
string b64 = Convert.ToBase64String(myBytes);
Console.WriteLine(b64);
// Convert back to bytes.
byte[] myBytes2 = Convert.FromBase64String(b64);
Console.WriteLine("myBytes.Length:"+myBytes2.Lengt h);

--
William Stacey, MVP
http://mvp.support.microsoft.com

"Timothy V" <tr****@msn.com> wrote in message
news:ua**************@TK2MSFTNGP09.phx.gbl...
Hi,
I have a byte[] that i want to convert into a string. I use the
BitConverter.ToString() method.

Now, how do I convert that string back into a byte[]?

Thanks in advance,

Tim.


Nov 16 '05 #3
You can use System.Text.Encoding.Default.GetBytes and
System.Text.Encoding.Default.GetString.

"Timothy V" <tr****@msn.com> wrote in message
news:ua**************@TK2MSFTNGP09.phx.gbl...
Hi,
I have a byte[] that i want to convert into a string. I use the
BitConverter.ToString() method.

Now, how do I convert that string back into a byte[]?

Thanks in advance,

Tim.

Nov 16 '05 #4

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

Similar topics

4
by: Greg Ennis | last post by:
If I run the following code: Byte bytes = System.Text.Encoding.ASCII.GetBytes("test"); return BitConverter.ToString(bytes); I get the string "74-65-73-74" back. My question is, what is the...
1
by: Gabe Jahn | last post by:
Basically I've used the BitConverter to convert a byte into a string. Now how do I convert it back to a byte? Hopefully without creating my own algorithm to accomplish this? Thanks...
5
by: george r smith | last post by:
Hi, I created a byte array --byte aByteArray = new byte; and set aByteArray and aByteArray to '1'. Because I want to create a ulong (UInt64) with these values I do: UInt64 bb; bb =...
0
by: Timothy V | last post by:
Hi, I have a byte that i want to convert into a string. I use the BitConverter.ToString() method. Now, how do I convert that string back into a byte? Thanks in advance, Tim.
1
by: Michael Davidov | last post by:
byte array = {0x00,0x04}; short ashort = BitConverter.ToInt16(array,0); Console.WriteLine(ashort.ToString()); Why am I wrong to think that this should return a 4 instead of 1024? Also, is...
7
by: Lenn | last post by:
This probably something stupid, or I am missing some fundemantal concept, but I can't figure this one out. Consider the following code: byte bd = new byte; bd = 0x00; bd = 0x01; ...
5
by: =?Utf-8?B?U3VzaGlTZWFu?= | last post by:
Hello. I have a problem with getting short value from 2 byte array. I have this code. There are 2 short values in bytes. byte cast = { 18, 152, 00, 80 }; Int32 port = BitConverter.ToInt16(cast,...
1
by: DR | last post by:
mySqlBytes.buffer is getting converted to BigEndian even though both SQL server 2005 and the CLR function are on the same machine which shows BitConverter.IsLittleEndian == true in tsql: select...
5
by: DaveD | last post by:
Can anyone help me get this compiled ? void Write<T>(T val) { byte bytes = BitConverter.GetBytes(val); Array.Reverse(bytes); writer.Write(bytes); } The problem is that for T=bool,...
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...
0
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...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
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)...
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
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...

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.