"Isliguezze" <(E-Mail Removed)> wrote in message
> Nice hack actually, bu I don't think that I do really understand this
>> test.xint = 'ABCD';
> What does it do? 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++?
The code just assigns a bit pattern to whatever the architecture defines as
an int. The example had nothing to do with your 8 + 8 + 1 problem. Sorry.
Also understand that, be they signed or unsigned, that characters typically
have the same number of bits. (I was surprised to ready of your problem.
Does not happen too offend!)
FWIW, consider running the snippet on Intel 32 - Notice how it actually
prints the characters backward - loosely reflects the underlying
architecture of the processor (little-endian.)
I was just a fun fact - er ... hack - Motorola would do something else. One
of the reasons why bit shifting / masking is a superior solution for your
particular problem. Also the reason for the irritated comments.
On Jun 25, 7:31 pm, Victor Bazarov <(E-Mail Removed)> wrote:
> James Kanze wrote:
> > [..]
> > int
> > from3Bytes( unsigned char* source )
> from3Bytes(unsigned char const* source) // 'const' just in case...
Yes. And not just in case; you want to be able to call the
function (without a const cast) from another function which
received the buffer as const.
James Kanze (GABI Software) email:(E-Mail Removed)
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