Hi everyone, I´m working on a project using a MSP430 device, and I started to love it, but the thing is I’m not proficient in C language, what I’m trying to do is what in BASIC now as the ASC() function
I want to show a Captured Byte in the LCD as an Hex value, and need to create the string with the Hex value of that char to show it on the LCD.
this is what I would do in BASIC
Function ShowValue (myvalue as byte)
dim mystr as string
mystr=Str(Asc(myvalue))
LCDout(mystr)
End Function
I already have the LCDout function working, so I only need the conversion.
The function you want is called itoa() (integer to ascii). You failed to mention what compiler you are using, but if you need to create the function from scratch, a simple google search on “itoa” should net you some code.
You can also use sprintf to format the string as well, but using printf/sprintf is generally frowned upon since it can take up a lot of code space.
That would be base 10. He wants hex, which would make it simpler to extract each digit, but adds a quirk when convertig it to ASCII, since you need to jump to the letters if the value is over 9.