# Thread: How to change number data from base 256 to base 16?

1. ## How to change number data from base 256 to base 16?

If I have these below data (base 256)

Code:
```data = 154; // 9A in base 16
data = 203; // CB in base 16
data = 15;   // 0F in base 16
data = 54;   // 38in base 16
data = 248; // F8 in base 16
data = 175; // AF in base 16```
and I want to change data(base 256) to Ctring which have format in base 16 character

Code:
```CString m_data;
m_data = "9ACB0F38F8AF";```
Do you know how to do that? 2. I think you mean you want to convert from base 10 to base 16...
where the base 10 number is between 0 and 255
I'll be back in a moment with code for that... 3. This should work.
It's not the most efficient, but it should be fairly easy to understand
Code:
```// converting the integer stored in data[i] to the for AB in hex.

int temp = data[i];
char first, second;
int units = temp % 16; // Units now holds an integer 0 to 15, this is the B part
temp = temp-units;
temp = temp*0.1;
temp = temp % 16; // Temp now holds an integer 0 to 15, this is the A part
// Now convert the two integers to characters.
switch(units)
{
case 0: second = '0'; break;
case 1: second = '1'; break;
// Other cases go in between
case 9: second = '9'; break;
case 10: second = 'A'; break;
// More cases in here
case 15: second = 'F'; break;
}
switch(temp)
{
// Same as before but into first.
}
cout<<data[i]<<" is "<<first<<second<<" in hex.";
// Do some code to put first and second into your cstring.``` Popular pages Recent additions 