Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I convert byte to string?

Tags:

c++

c#

Is there any fast way to convert given byte (like, by number - 65) to it's text hex representation?

Basically, I want to convert array of bytes into (I am hardcoding resources) their code-representation like

BYTE data[] = {0x00, 0x0A, 0x00, 0x01, ... }

How do I automate this Given byte -> "0x0A" string conversion?

like image 543
Yippie-Ki-Yay Avatar asked Jul 14 '26 20:07

Yippie-Ki-Yay


1 Answers

In C++, you can use stringstream, and ssprintf.

Some compilers may have an itoa method that will convert an integer into its textual representation.

These are portable functions. You can always add an integer to '0' to get a textual digit and likewise with 'A' and 'a'.

like image 128
Thomas Matthews Avatar answered Jul 16 '26 10:07

Thomas Matthews



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!