Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

filling a char manualy

1 view
Skip to first unread message

maarten.de...@gmail.com

unread,
Jul 2, 2007, 6:42:49 AM7/2/07
to
Hello,

I'm making a function that takes a pointer to a char and an integer to
store in there. (And two opional value's to change where to put the
int in the char). So if I aInt=257, start=0 and len=4 this code does
char[0]=0x00;
char[1]=0x00;
char[2]=0x01;
char[3]=0x01;
and ends up with 0x00000101

The string result is just for debugging. The string ended up as it
should, namely 0 0 1 1. And I also tested it with different values.
But when the line buf[i+start]=## runs, the char suddenly reduces its
lenght so that buf[0] is the only one. When I replaced it with
buf[1+start]=1; it worked no problem. But when I set the first one to
0 the rest dissapear. I tested it with buf[1+start]=0; That reduces
it's lenght. Why does that happen? Do they terminate after a 0 byte?
And if they do, how can I store an integer of fixed length in a char?

Kind regards,
Maarten

void TForm1::Int2Char(int aInt, char* buf, int start, int len)
{
long int bitmask=0;
AnsiString result=" ";
int btn=0;
for (int i=0; i<len; i++){
btn=(len-i)-1;
bitmask=0xFF << (btn*8);
buf[i+start]=(aInt&bitmask)>>(btn*8);
result+=" "+AnsiString((aInt&bitmask)>>(btn*8));
}
bitmask=0;
}

maarten.de...@gmail.com

unread,
Jul 3, 2007, 5:28:25 PM7/3/07
to
I decided to use a TMemoryStream, so nevermind.

Maarten

0 new messages