8-bit char in hexadecimal representation

I am trying to convert 8 bits charto a hexadecimal representation that looks like this:

00 03 80 45 E5 93 00 18 02 72 3B 90 88 64 11 00 
45 FF 00 36 00 FF 45 00 00 34 7B FE 40 00 40 02

But some characters contain negative values ​​that make the larger hexadecimal value more than two digits. how would i get each as above?

+3
source share
2 answers

, , , char ( , char - 8 , ), . BYTE typedef. boost::uint8_t . :

char c=-25; // Oh no, this is one of those pesky "negative" characters
unsigned char byteVal=static_cast<unsigned char>(c); // FTFY

// Do the formatting with byteVal
+4

" " - , - , , char, 8 . 0-255 00 FF.

0

Source: https://habr.com/ru/post/1792417/


All Articles