SparkFun Forums 

Where electronics enthusiasts find answers.

Discussions on how to get your MSP JTAG programmer up and running.
By animo3d
#80865
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.

any ideas?

thanks
By TheDirty
#80870
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.
By OldCow
#80880
If you just want to convert a byte into 3 digits in ASCII, try this:

dig[0]=byte/100+'0';
dig[1]=byte%100/10+'0';
dig[2]=byte%10+'0';
By animo3d
#80883
Oh yes I forget to mention the compiler, i'm using ImageCraft

and thanks OldCow, that should do the trick,

I will test it an let you know!
By TheDirty
#80891
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.
By OldCow
#80895
Some time people do not mean what they say.

Asc() in BASIC does not do what he said but probably does what he wanted.
By TheDirty
#80930
Good catch. I thought it was just suggested code rather than literal, since he specifically said hex.
By animo3d
#80934
Hex or dec I only need to monitor the value, that worked for me.

thanks