Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Convert from byte array to string hex c# [duplicate]

Suppose I have byte array.

byte[] a = new byte[] {0x33,0x43,0xFE};

I want to convert it to string.

 string str = convert(a);  

My str should look like this:

"33 43 FE"

How can I do that?

like image 529
cheziHoyzer Avatar asked Apr 30 '13 12:04

cheziHoyzer


People also ask

How do you convert a byte array to a hexadecimal string?

To convert byte array to a hex value, we loop through each byte in the array and use String 's format() . We use %02X to print two places ( 02 ) of Hexadecimal ( X ) value and store it in the string st . This is a relatively slower process for large byte array conversion.

What is a Hexstring?

Hexadecimal Number String. The “Hexadecimal” or simply “Hex” numbering system uses the Base of 16 system and are a popular choice for representing long binary values because their format is quite compact and much easier to understand compared to the long binary strings of 1's and 0's.

What is a ByteArray?

ByteArray is an extremely powerful Class that can be used for many things related to data manipulation, including (but not limited to) saving game data online, encrypting data, compressing data, and converting a BitmapData object to a PNG or JPG file.


1 Answers

use bitconverter class

 BitConverter.ToString(Bytes);
like image 165
Shafqat Masood Avatar answered Nov 21 '22 15:11

Shafqat Masood