Can anybody explain me below statement ?
-
sscanf(strValue + 2i, "%02x", &bytearray[i]);
where strValue = " B7D2E40383FB42397357C80DF39B8CF0";
& bytearray declared like below :
unsigned char bytearray[20];here strValue [0] and strValue [1] both are combinedly get store into bytearray[0].
above statement is not set into my mind. i want to know how it combine 2 string char into one byte.
i know that second argument of sscanf is doing this but i not know what exactly %02x do ?
-
sscanf(strValue + 2i, "%02x", &bytearray[i]);
where strValue = " B7D2E40383FB42397357C80DF39B8CF0";
& bytearray declared like below :
unsigned char bytearray[20];here strValue [0] and strValue [1] both are combinedly get store into bytearray[0].
above statement is not set into my mind. i want to know how it combine 2 string char into one byte.
i know that second argument of sscanf is doing this but i not know what exactly %02x do ?
@Qt-embedded-developer said in Can anybody explain me below statement ?:
%02x
This tells it to read 2 characters, treat it as a (2-digit) hexadecimal number-string, convert to number (0x00--0xff) and store the number as (one byte in)
bytearray[i]
.If you put it inside an
i
loop it will go along reading 2 characters at a time fromstrValue
, converting them to a single byte to be stored atbytearray[i]
. -
@JonB how to do of same thing for (2-digit) hexadecimal number-string , treat it as read 2 characters
-
@JonB how to do of same thing for (2-digit) hexadecimal number-string , treat it as read 2 characters
@Qt-embedded-developer said in Can anybody explain me below statement ?:
how to do of same thing for (2-digit) hexadecimal number-string , treat it as read 2 characters
Please rephrase, it is really hard to understand
-
@Qt-embedded-developer said in Can anybody explain me below statement ?:
how to do of same thing for (2-digit) hexadecimal number-string , treat it as read 2 characters
Please rephrase, it is really hard to understand
@jsulm how to split this hexadecimal number string into 2 separate char ?
hexnumber char array[ 0] char array[1]
0xbd --> b d -
@jsulm how to split this hexadecimal number string into 2 separate char ?
hexnumber char array[ 0] char array[1]
0xbd --> b d@Qt-embedded-developer
If you already have the two chars in "char array[ 0] char array[1]" then you already have your answer.
If you start with a number then use e.g.QString,arg(yournum, 2, 16, 0)
, see https://doc.qt.io/qt-6/qstring.html#arg-3.