I have a hex value that is entered on the command line.
./test 0x50800460280250a9
What would be the best way to convert /parse? I need to use this hex value.
I have a hex value that is entered on the command line.
./test 0x50800460280250a9
What would be the best way to convert /parse? I need to use this hex value.
What's wrong with sscanf()?
Edit2: Removed bullsh...
Last edited by TactX; 01-12-2006 at 03:38 PM.
Code:int i = strtol(argv[1],NULL,0);
That number is too big for any C normal size integer 64-bit or smaller. This compiles but displays the wrong number
Code:int main(int argc, char* argv[]) { unsigned _int64 n = 0x50800460280250a9; printf("%u64\n", n); return 0; }
Assuming that your compiler supports long long ints, something like:will work for values that can be expressed in 64 bits. Values beyond that must be handled using arbitrary number packages, which are not a standard part of the C library.Code:long long cmdval = strtoll(argv[1], NULL, 0);
Last edited by filker0; 01-12-2006 at 05:12 PM. Reason: reread the Ancient_Dragon's remark
Insert obnoxious but pithy remark here
AD: shouldn't it be...?
(I needed such changes for gcc anyways.)Code:unsigned __int64 n = 0x50800460280250a9; printf("%I64x\n", n);
7. It is easier to write an incorrect program than understand a correct one.
40. There are two ways to write error-free programs; only the third one works.*
>>int i = strtol(argv[1],NULL,0);
unsigned long long i = strtoull ((argv[1],NULL,16);
The above provided what I need.
Thanks!
A long long is at least 64 bits, capable of holding values upto at least 0x7FFFFFFFFFFFFFFF. This is greater than 0x50800460280250a9.Originally Posted by Ancient Dragon