Quoting Peter Stuge <peter at stuge.se>:
> On Wed, Jul 04, 2007 at 09:22:54AM -0400, Joseph Smith wrote:
>> Hello,
>> 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 */
>> if(0xac==0254)
> 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.
>>> //Peter
>> --
> linuxbios mailing list
>linuxbios at linuxbios.org>http://www.linuxbios.org/mailman/listinfo/linuxbios>>
Ok so how would I go about doing this is print_debug than?
Something like:
value=0xff; /* hexadecimal */
/* %d means print number in decimal */
print_debug("value in decimal is now %d\n",value);
Thanks - Joe