Avatar of kakali
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.strMerchantID.Format("%016d",_atoi64(m_objDeviceDetail.strMerchantID));

lngTemp=_atoi64(m_objDeviceDetail.strMerchantID);

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
C++

Avatar of undefined
Last Comment
Infinity08

8/22/2022 - Mon
ASKER CERTIFIED SOLUTION
zhuba

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
kakali

ASKER
Many thanks. Yes this is the right solution.
Infinity08

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.
All of life is about relationships, and EE has made a viirtual community a real community. It lifts everyone's boat
William Peck