Is there a simple way to convert numbers between these two bases, or do I need to write code to do it!
Thanks.
Conversion dec to hex and hex to dec
- rbytes
- Posts: 1338
- Joined: Sun May 31, 2015 12:11 am
- My devices: iPhone 11 Pro Max
iPad Pro 11
MacBook
Dell Inspiron laptop
CHUWI Plus 10 convertible Windows/Android tablet - Location: Calgary, Canada
- Flag:
- Contact:
Conversion dec to hex and hex to dec
The only thing that gets me down is gravity...
- Mr. Kibernetik
- Site Admin
- Posts: 4786
- Joined: Mon Nov 19, 2012 10:16 pm
- My devices: iPhone, iPad, MacBook
- Location: Russia
- Flag:
Re: Conversion dec to hex and hex to dec
Can you please give an example of what kind of conversion do you need? Some kind of pseudo code which imitates desired behavior.
- rbytes
- Posts: 1338
- Joined: Sun May 31, 2015 12:11 am
- My devices: iPhone 11 Pro Max
iPad Pro 11
MacBook
Dell Inspiron laptop
CHUWI Plus 10 convertible Windows/Android tablet - Location: Calgary, Canada
- Flag:
- Contact:
Re: Conversion dec to hex and hex to dec
I found that SPL already converts hex to decimal automatically. If I run the line
#.output(ffh) it will print 255. If I run the line g = ffh, g will equal 255
What I want is a function that will convert decimal to hex, so that when my Unicode reader returns the decimal value of a character, I can convert that to a high and low byte for the user. They can then use your hex byte system to reproduce the character.
In other words a decimal value would need to be converted as follows. t = hex(255). The output should then be “ffh”. I assume the hex function would have to return a string value; otherwise if t was treated as a numeric variable, as soon as I tried to read t, its value would be decimal 255.
I found the following website that gives me the formula in C. I could try to translate that into SPL if there is no current function to do it.
http://scanftree.com/programs/c/c-code- ... xadecimal/
#.output(ffh) it will print 255. If I run the line g = ffh, g will equal 255
What I want is a function that will convert decimal to hex, so that when my Unicode reader returns the decimal value of a character, I can convert that to a high and low byte for the user. They can then use your hex byte system to reproduce the character.
In other words a decimal value would need to be converted as follows. t = hex(255). The output should then be “ffh”. I assume the hex function would have to return a string value; otherwise if t was treated as a numeric variable, as soon as I tried to read t, its value would be decimal 255.
I found the following website that gives me the formula in C. I could try to translate that into SPL if there is no current function to do it.
http://scanftree.com/programs/c/c-code- ... xadecimal/
The only thing that gets me down is gravity...
- Mr. Kibernetik
- Site Admin
- Posts: 4786
- Joined: Mon Nov 19, 2012 10:16 pm
- My devices: iPhone, iPad, MacBook
- Location: Russia
- Flag:
Re: Conversion dec to hex and hex to dec
This is done using #.str function:
#.output(#.str(255,"X"))
SPL has very advanced formatting options which are given in Appendix 1.
#.output(#.str(255,"X"))
SPL has very advanced formatting options which are given in Appendix 1.