473,396 Members | 2,068 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.

convert to array of byte

Hello group,
I've string :"A1 10 15 06 87 FF 10" etc. this are hex value of character.
How convert this string to array of byte :

System.Byte[] arrBytes = new byte[50];

Thx
PawelR
Nov 16 '05 #1
3 1643
Check out String.Split() to split the string into array of HEX-numbers
{"A1", "10",...} and use Byte.Parse() to convert to byte:

Byte b = Byte.Parse("A1", System.Globalization.NumberStyles.HexNumber); //
b = 161

Lars Moastuen
On Mon, 2 Aug 2004 14:13:24 +0200, PawelR <pa************@poczta.onet.pl>
wrote:
Hello group,
I've string :"A1 10 15 06 87 FF 10" etc. this are hex value of character.
How convert this string to array of byte :

System.Byte[] arrBytes = new byte[50];

Thx
PawelR


--
Using Opera's revolutionary e-mail client: http://www.opera.com/m2/
Nov 16 '05 #2
Hi PawelR,

As Lars said, you can do it with String.Split and then parse the value.

An alternate way which basically does exactly the same is

string s = "A1 10 15 06 87 FF 10";

string[] sa = s.Split(' ');
byte[] b = new byte[sa.Length];

for(int i = 0; i < sa.Length; i++)
b[i] = Convert.ToByte(sa[i],16);

--
Happy coding!
Morten Wennevik [C# MVP]
Nov 16 '05 #3
Thx Lars and Morten

PawelR
Uzytkownik "Morten Wennevik" <Mo************@hotmail.com> napisal w
wiadomosci news:opsb3uf4lzklbvpo@morten_x.edunord...
Hi PawelR,

As Lars said, you can do it with String.Split and then parse the value.

An alternate way which basically does exactly the same is

string s = "A1 10 15 06 87 FF 10";

string[] sa = s.Split(' ');
byte[] b = new byte[sa.Length];

for(int i = 0; i < sa.Length; i++)
b[i] = Convert.ToByte(sa[i],16);

--
Happy coding!
Morten Wennevik [C# MVP]

Nov 16 '05 #4

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

Similar topics

19
by: jeff | last post by:
how do you convert form byte to Int32 while retaining the binary value of the byte array
1
by: Swarup | last post by:
I am reading a file (txt, xml, gif, ico, bmp etc) byte by byte and filling it into a byte arry. Now i have to convert it into a string to store it in the database. I use...
6
by: Ricardo Quintanilla | last post by:
i have a code that sends data to a socket listening over as400 platform, the socket responds to me as a "byte array". then i need to convert the "byte array" into a string. the problem is that...
3
by: MuZZy | last post by:
Hi, I just wonder if someone can help me wit this - i have a byte array and need to convert it to short array, creating short numbers by combining bytes by pairs: My array: byte, byte, byte,...
15
by: Kueishiong Tu | last post by:
How do I convert a Byte array (unsigned char managed) to a char array(unmanaged) with wide character taken into account?
6
by: moondaddy | last post by:
I'm writing an app in vb.net 1.1 and need to convert a byte array into a string, and then from a string back to a byte array. for example Private mByte() as New Byte(4){11,22,33,44} Now how...
12
by: Peter | last post by:
Trying to convert string to byte array. the following code returns byte array of {107, 62, 194, 139, 64} how can I convert this string to a byte array of {107, 62, 139, 65} ...
19
by: est | last post by:
From python manual str( ) Return a string containing a nicely printable representation of an object. For strings, this returns the string itself. The difference with repr(object) is that...
5
by: da1978 | last post by:
Hi experts, I need to convert a string or a Byte array to a string byte array. Its relatively easy to convert a string to an char array or a byte array but not a STRING byte array. i.e. ...
0
Debadatta Mishra
by: Debadatta Mishra | last post by:
Introduction In this article I will provide you an approach to manipulate an image file. This article gives you an insight into some tricks in java so that you can conceal sensitive information...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
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...
0
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,...

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.