On Jun 25, 4:28 pm, Isliguezze <isligue...@gmail.com> wrote:
> Nice hack actually, bu I don't think that I do really understand this
> string:
> > test.xint = 'ABCD';
> What does it do?
Whatever the implementation wants it to do. You'll have to look
up the documentation of your implementation to find out.
In general, multibyte character literals are a misfeature, still
supported for reasons of backward compatibility, but not
something anyone should use, or even worry about understanding.
> I need to convert 17 bit int to three unsigned chars
> in such way to have it all look like this: 8 bits + 8 bits + 1 bit,
> and how to restore them back to an int? I didn't hear proper answer,
> how do I do that in C++?
Someone did mention shifting and the bitwise operators, it
seems. But you've not really specified enough: which bits
belong in what character. If I suppose network byte order, and
put the bit 16 (the high order bit) in the first byte, the
correct answer would be something like:
void
to3Bytes( unsigned char* dest, int value )
{
assert( value >= 0 && value < (1 << 17 ) ) ;
dest[ 0 ] = (value >> 16) & 0xFF ;
dest[ 1 ] = (value >>

& 0xFF ;
dest[ 2 ] = (value ) & 0xFF ;
}
int
from3Bytes( unsigned char* source )
{
return dest[ 0 ] << 16
| dest[ 1 ] << 8
| dest[ 2 ] ;
}
--
James Kanze (GABI Software) email:
Conseils en informatique orientée objet/
Beratung in objektorientierter Datenverarbeitung
9 place Sémard, 78210 St.-Cyr-l'École, France, +33 (0)1 30 23 00 34