Re: hex to int



Bill Cunningham wrote:
"Bill Cunningham" <nospam@xxxxxxxxxxxxx> wrote in message
news:49a1ba14$0$5470$bbae4d71@xxxxxxxxxxxxxxxxxxxxxx
I have written this small program and I must admit I'm a little
stuck. Input should be a hex number like fff or 0xfff and convert it
to the decimal equivalent. The output I get is always 0.

#include <stdio.h>
#include <stdlib.h>

int main(int argc, char **argv)
{
if (argc != 2) {
puts("hex usage error");
exit(EXIT_FAILURE);
}
int x = strtol(argv[1], NULL, 10);
printf("%i\n", x);
return 0;
}

Am I missing a std function here that could do this for me? I know
error checking is not present.

Bill

I see that strtol returns a long. Could this be part of the
problem?

No. See my other post
.



Relevant Pages

  • Re: hex to int
    ... Bill Cunningham wrote: ... stuck. ... Input should be a hex number like fff or 0xfff and convert it ... to the decimal equivalent. ...
    (comp.lang.c)
  • Re: Binary Trees addNode routines
    ... It states my stack is ... |0x4096 Hex. ... 4096 is the decimal equivalent for 4K. ... As a man who holds a Communications education, ...
    (comp.lang.asm.x86)
  • Re: addresses
    ... Bill Cunningham wrote: ... variable and use that address within the context of the application. ... Perhaps what I'm thinking of is a kernel function and the kernel mapping ... to print something in hex, ...
    (comp.lang.c)
  • Re: 0x800700B6 error message
    ... >>You could also try searching for the decimal equivalent of that hex value. ... >>Unfortunately nobody will tell me whether the hex value is to be interpreted ...
    (microsoft.public.windowsupdate)
  • Re: Binary Trees addNode routines
    ... |0x4096 Hex. ... 4096 is the decimal equivalent for 4K. ... to 16-bit realmode seg:offset ... mov ax,8000h ...
    (comp.lang.asm.x86)