I have a binary array with hex values and I would like to convert it into decimal. Once that is done I would like to display it in a string.
BTW, I am working on an intel process via ubuntu and this will probably be used on a sun many hp unix box.
When I do a straight up assignment to unsigned long it works... as in the decimal part. I still have not made that into a string yet, but I am not sure why it works. Furthermore I read somewhere that when you put it in unsigned long the you will not have to worry about endianess.
Could I get some help on how to take this issue and why the aforementioned works as well?
please note: I am using c++ and not the .net stuff so bitconverter is not available.
EDIT (Copied from answer to own question below)
first of all thanks for the endian link that IBM article really helped. knowing that i was just putting it into a register rather than manually putting the byte values in consecutive memory locations is what takes away the whole endianess issue made a big difference.
here is a piece of code that I wrote which I know can be better but its just something quick...
// use just first 6 bytes
byte truncHmac[6];
memset( truncHmac, 0x00, 6 );
unsigned long sixdigit[6];
for (int i=0; i<=5; i++)
{
truncHmac[i]=hmacOutputBuffer[i];
sixdigit[i]=truncHmac[i];
std::cout<<sixdigit[i]<< std::endl;
}
the output is
HMAC: 76e061dc7512be8bcca2dce44e0b81608771714b
118
224
97
220
117
18
which makes sense that its take the first six bytes and converting them to decimals.
The only question I have now is how to make this into a string. Someone mentioned using manipulators? Could I get an example?