Is there single line syntax for converting hex into decimal number??(Type casting)
unsigned char* data_1;
data_1 = 0x01; //contains hex value
a = data_1; //want to convert hex value in decimal
Are you sure you actually need to do any conversion?
int a = 0xD431;
int b = 54321;
cout << "a: " << a << endl;
cout << "b: " << b << endl;
a and b are unrelated integer values.
When the value is output, we see it in decimal.
But internally they are both stored in binary. There is no need to explicitly convert anything in this example.
By the way, the original code has an uninitialised pointer
. Since this does not point to a valid address, attempting to assign data to it will give rise to unpredictable results.
Last edited on