HelpPlsHow to convert large chars to integer and hex
| swordfish622 (7) | |||
| Pls. help me I need to convert large char to numeric and hex, below are the requirements: input: char var_char = '9999999999999999' ---16 max length-- output: 9999999999999999 ---- integer type 2386F26FC0FFFF ----- hex value using sprintf cuts the value of hex, would appreciate your help... thanks i really need this to catch the deadline... | |||
| msram (19) | |||
If you are sure that the number of digits is not more than 16, then you can use
long long int data type if your compiler supports it. It's a 64 bit data type.
Please see the following pages for more details: http://home.att.net/~jackklein/c/inttypes.html#long_long http://docs.freebsd.org/info/gcc/gcc.info.Long_Long.html http://cboard.cprogramming.com/showthread.php?p=666259 | |||
| ropez (312) | |||
Or if you want to use C++ methods instead of C:
| |||
| swordfish622 (7) | |||
| tried it on visual c++ 6.0 error below: Compiling... char_hex.cpp d:\temp1\char_hex.cpp(5) : error C2632: 'long' followed by 'long' is illegal Error executing cl.exe. char_hex.exe - 1 error(s), 0 warning(s) | |||
| ropez (312) | |||
| If you can, you should replace VC6 with Visual C++ 2008 Express, which is free. VC6 is known to have poor standard compliance. Anyway, I think you'll need to use something like "__int64" instead of long long int. (that is: two underlines followed by int64) | |||
| swordfish622 (7) | |||
| #include<stdio.h> int main() { char char_num[17]; __int64 int_num; char new_val[]={NULL}; printf("Enter a number (Max 16 digits) : "); scanf("%16s",char_num); sscanf(char_num,"%lld",&int_num); sprintf(new_val,"%llX",int_num); printf("\n%s new_value\n",new_val); printf("\n%lld %llX\n",int_num,int_num); return 0; } output: Enter a number (Max 16 digits) : 999999999999999 A4C67FFF new_value 1179010615 CCCCCC00 Press any key to continue ---new_val should be "38D7EA4C67FFF" ... this is what i'm referring it cuts the output value... | |||
| Grey Wolf (637) | |||
| __int64 is available in VC6 but I don't think it will like the << >> operators, as ropez said poor standard compliance. To clarify, That is the stringstream >> operator I don’t think there is a 64bit implementation of it and the cout <<gets confused with a 64bit int. | |||
| swordfish622 (7) | |||
| got it working on bit64 system ... thanks really appreciate your support | |||
This topic is archived - New replies not allowed.
