[LinuxBIOS] Convert hex to dec
joe at smittys.pointclark.net
Wed Jul 4 22:36:57 CEST 2007
Quoting Peter Stuge <peter at stuge.se>:
> On Wed, Jul 04, 2007 at 09:22:54AM -0400, Joseph Smith wrote:
>> Got another silly C newbie question.
>> If I want to convert a hex value to decimal, would this work?
>> value = ff /* Hex value */
>> sscanf(value, %d, &value)
>> Is the variable "value" now 255??
> Hexadecimal, decimal and octal are different ways for us humans to
> express numbers to computers, but no matter what we use, they are
> always stored in binary form in the machine.
> Thus, there is no difference between a number in hexadecimal or
> decimal. We do however have to tell the computer which formatting we
> want when the computer should show us the numbers.
> unsigned char value;
> value=0xff; /* hexadecimal */
> /* %d means print number in decimal */
> printf("value in decimal is now %d\n",value);
> value=135; /* decimal */
> /* %x means print in hex */
> printf("value in hexadecimal is now %x\n",value);
> value=0254; /* octal */
> printf("C knows that 0xac == 0254 because they are both == %d\n",value);
> Have a look at the printf man page for your nearest C library to
> learn about all the good stuff you can put into formatting strings
> besides just %d and %x.
> linuxbios mailing list
> linuxbios at linuxbios.org
Ok so how would I go about doing this is print_debug than?
value=0xff; /* hexadecimal */
/* %d means print number in decimal */
print_debug("value in decimal is now %d\n",value);
Thanks - Joe
More information about the coreboot