TUint32 to TBuf8

Login to reply to this topic.
Sat, 2005-05-21 05:52
Joined: 2004-10-17
Forum posts: 85
How can I convert a TUint32 number to TBuf8<4>?

So if I have:

TUint32 num(0xaabbccdd)

it should convert to:

TBuf8<4> buf;

buf(0) = 'dd'
buf(1) = 'cc'
buf(2) = 'bb'
buf(3) = 'aa'


Using "buf.Format(_L8("%x"), num)" gets me 8 8-bytes.. so I get buf(0) = 'd', buf(1) = 'd', buf(2) = 'c', ..., buf(7) = 'a'.
But that's not what I want.


Sat, 2005-05-21 09:18
Joined: 2004-12-03
Forum posts: 192
Re: TUint32 to TBuf8
symbol takes one byte
so if you want to keep `dd` you need 2 bytes
Sat, 2005-05-21 10:04
Joined: 2004-06-06
Forum posts: 205
Re: TUint32 to TBuf8
you can use TPtr.
for ex.:
Code:
TInt bufsize = 1024;
TUint32 * myIntBuf[bufsize]
// Fill your myIntBuf
//
TPtr8 myIntDes( (TUint8 *) myIntBuf, bufsize*4,bufsize*4);

Best regards,
Michal Laskowski

Sat, 2005-05-21 20:58
Joined: 2004-10-17
Forum posts: 85
Re: TUint32 to TBuf8
In case anyone wants to know, the following code does exactly what I asked for:

Code:
TUint32 myIntBuf(0xaabbccdd);
TPtr8 ptr(reinterpret_cast<TUint8*>(&myIntBuf), sizeof(myIntBuf), sizeof(myIntBuf));
TBuf8<4> buf;
buf.Append(ptr);
  • Login to reply to this topic.