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... 1 3407
Gabe Jahn <gj***@algor.co m> wrote: 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?
With BitConverter.To String you'll have ended up with a dash-separated
hex value list. I don't know of an easy way of reversing that. (Well,
"one line" - it's not that hard to reverse it really.)
If you change to use Convert.ToBase6 4String then you can easily reverse
it using Convert.FromBas e64String and it's slightly more compact as
well :)
--
Jon Skeet - <sk***@pobox.co m> http://www.pobox.com/~skeet/
If replying to the group, please do not mail me too This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
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
easiest way to convert the string back to "test"?
Can it be done without breaking the string and using a loop, etc.? I
have tried many methods, but can't find a way without using a loop. It
|
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 = BitConverter.ToUInt64(aByteArray,0);
Console.WriteLine(bb);
|
by: Opa1 |
last post by:
using BitConverter.ToString() in Compact Framework has some bugs.
The resulting hex string does not have a consistent format for each
byte converted from the input byte array.
for example:
Byte array with values,
(9,0,0,0,115,105,103,110,97,116,117,114,101,224,0,0,0,51,0,0,0,1)
result in,
|
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.
|
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 there a way to get a short value of 4 from those 2 bytes
without switching their possition in the byte array?
| |
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;
System.Int16 a;
|
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, 0); // -26606 - wrong!
Int32 port2 = BitConverter.ToInt16(cast, 2); // 20480 - wrong!
//port and port2 get not correct values
//and I found solution in google
short result1 = (short)(((short)cast) | (short)(cast * 256)); //4760 -
|
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 * from dbo.MY_CLR_FUNCTION(cast(1024 as binary(4)))
public static int MY_CLR_FUNCTION(SqlBytes mySqlBytes)
in debugger binaryData.buffer now shows bigendian!!
0 byte
|
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, BitConverter.GetBytes(bool) won't
compile. In C++ I would have created an explicit instantiation like
|
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...
|
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,...
| |
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...
|
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...
|
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...
|
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...
|
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();...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |
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...
| |