Any code to take 2 ascii chars and put into 1 byte?
0x16 = ? byte
Are you having a problem with understanding the math?
In decimal, another way to write 123 is:123 = 1*10^2 + 2*10^1 + 3*10^0
Same argument can be made for hex:0x17 = 1*16^1 + 7*16^0 = 23
Programming this should be easy. Try it.
no thats not it..
i mean
Hex 2a
char a = getc() // '2'
char b = getc() // 'a'
0x2a = 42
I want to assign
byte = 42
What part are you having problems with?
You've read 2 characters representing the digits of a hex number.
Now you need to convert them from characters to integers.
And then you use the formula: byte = d_n*b^n + ... + d_0*b^0
where byte is a uint8_t.
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.