For example , 130ABF (Hexadecimal) is equals to 1247935 (Decimal), So my byte array is
char buf[3] = {0x13 , 0x0A , 0xBF};
and I need to retrieve the decimal value from the byte array.
Below are my sample code:
#include<iostream>
using namespace std;
int main()
{
char buf[3] = {0x13 , 0x0A , 0xBF};
int number = buf[0]*0x10000 + buf[1]*0x100 + buf[2];
cout<<number<<endl;
return 0;
}
and the result is : (Wrong)
1247679
Unless I change the
char buf[3] = {0x13 , 0x0A , 0xBF};
to
int buf[3] = {0x13 , 0x0A , 0xBF};
then It will get correct result.
Unfortunately, I must set my array as char type, anyone know how to solve this ?