kakali
asked on
ASCII to Byte Conversion
Hi,
I have a field whose decimal value is 36. I want to convert it to a 8 byte stream which will be represented as "00 00 00 00 00 00 00 24".
Now following is my code:
m_objDeviceDetail.strMerch antID.Form at("%016d" ,_atoi64(m _objDevice Detail.str MerchantID ));
lngTemp=_atoi64(m_objDevic eDetail.st rMerchantI D);
if (lngTemp==0) return false;
ch=((lngTemp>>56) & 0xff);
strQBext.SetAt(0,ch);
ch=((lngTemp>>48) & 0xff);
strQBext.SetAt(1,ch);
ch=((lngTemp>>40) & 0xff);
strQBext.SetAt(2,ch);
ch=((lngTemp>>32) & 0xff);
strQBext.SetAt(3,ch);
ch=((lngTemp>>24) & 0xff);
strQBext.SetAt(4,ch);
ch=((lngTemp>>16) & 0xff);
strQBext.SetAt(5,ch);
ch=((lngTemp>>8) & 0xff);
strQBext.SetAt(6,ch);
ch=(lngTemp & 0xff);
strQBext.SetAt(7,ch);
But the out put I am getting is "00 00 00 24 00 00 00 24".
Can anyone help me to find out what should I do to get the desired result which is "00 00 00 00 00 00 00 24".
Thanks in advance
I have a field whose decimal value is 36. I want to convert it to a 8 byte stream which will be represented as "00 00 00 00 00 00 00 24".
Now following is my code:
m_objDeviceDetail.strMerch
lngTemp=_atoi64(m_objDevic
if (lngTemp==0) return false;
ch=((lngTemp>>56) & 0xff);
strQBext.SetAt(0,ch);
ch=((lngTemp>>48) & 0xff);
strQBext.SetAt(1,ch);
ch=((lngTemp>>40) & 0xff);
strQBext.SetAt(2,ch);
ch=((lngTemp>>32) & 0xff);
strQBext.SetAt(3,ch);
ch=((lngTemp>>24) & 0xff);
strQBext.SetAt(4,ch);
ch=((lngTemp>>16) & 0xff);
strQBext.SetAt(5,ch);
ch=((lngTemp>>8) & 0xff);
strQBext.SetAt(6,ch);
ch=(lngTemp & 0xff);
strQBext.SetAt(7,ch);
But the out put I am getting is "00 00 00 24 00 00 00 24".
Can anyone help me to find out what should I do to get the desired result which is "00 00 00 00 00 00 00 24".
Thanks in advance
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Let me get this right ... You have a 64 bit value, and want to convert it to a stream of 8 bytes ?
If so, you can simply copy the 64 bit value into your 8 bytes. Don't forget to take into account the endianness (byte ordering).
There's no need for arithmetic operations like shifting - simply copy the bytes.
If so, you can simply copy the 64 bit value into your 8 bytes. Don't forget to take into account the endianness (byte ordering).
There's no need for arithmetic operations like shifting - simply copy the bytes.
ASKER