I am trying to convert a BYTE array to the equivalent value of unsigned long long int, but my encoding is not working properly. Help with fixing it or suggest an alternative method for this.
Additional information: these 4 bytes are combined as a hexadecimal number, and the equivalent decimal number is the result. Say for a given byte, Array = {0x00, 0xa8, 0x4f, 0x00}, the hexadecimal number is 00a84f00, and its equivalent decimal number is 11030272.
#include <iostream>
#include <string>
typedef unsigned char BYTE;
int main(int argc, char *argv[])
{
BYTE byteArray[4] = { 0x00, 0x08, 0x00, 0x00 };
std::string str(reinterpret_cast<char*>(&byteArray[0]), 4);
std::cout << str << std::endl;
unsigned long long ull = std::strtoull(str.c_str(), NULL, 0);
printf ("The decimal equivalents are: %llu", ull);
return EXIT_SUCCESS;
}
I get the following output:
The decimal equivalents are: 0
So far, the expected result has been:
The decimal equivalents are: 2048
source
share