Page 1 of 1

Converting a byte to ASCII

Posted: Tue Oct 13, 2020 7:43 pm
by Clive44
Hi

I'm reading the internal part number number of a device over I2C.
The part number is in the form HDL12345678 and it is transmitted character by character as ASCII ie H = 72, D = 68, L =76 etc
I want to store this in a string variable 11 characters long.
i.e. StringVar = StringVar + ASCII(byte)
So StringVar will end up as "HDL12345678" after receiving the I2C data byte by byte.
I seem to have a mental block on how to do this. !!!

Any help appreciated

Clive44

Re: Converting a byte to ASCII

Posted: Tue Oct 13, 2020 7:47 pm
by mnf
In pseudocode...

Code: Select all

.pos = 0
for number_of_bytes_needed
    .str[.pos] = .char (read from i2c)
    .pos = .pos + 1
end loop
.str[.pos] = 0   / Mark end of string
Make sure the string is large enough to hold the data plus the termination character.

Martin