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
Converting a byte to ASCII
Moderator: Benj
-
- Valued Contributor
- Posts: 1189
- Joined: Wed May 31, 2017 11:57 am
- Has thanked: 70 times
- Been thanked: 439 times
- Contact:
Re: Converting a byte to ASCII
In pseudocode...
Make sure the string is large enough to hold the data plus the termination character.
Martin
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
Martin