Re: unpacking ints
From: Karl Heinz Buchegger (kbuchegg_at_gascad.at)
Date: 03/02/04
- Next message: NKOBAYE027: "Re: weird #define statement"
- Previous message: Datta Patil: "Re: How to prevent a class from being inheritable, in C++"
- In reply to: Alberto Barbati: "Re: unpacking ints"
- Next in thread: Alberto Barbati: "Re: unpacking ints"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Tue, 02 Mar 2004 14:19:21 +0100
Alberto Barbati wrote:
>
> Karl Heinz Buchegger wrote:
> >>Is my method above for unpacking the int correct?
> >
> > The casts are wrong. You need to cast the individual bytes to unsigned int
> > first and cast the total result to int only after the number is constructed.
>
> Wrong. You need to cast the individual bytes to unsigned char not
> unsigned int. Otherwise a signed char will be promoted to (signed) int
> before being converted to unsigned int.
Right.
I assumed that anybody working at the bytelevel uses unsigned char
to store bytes and not plain char.
-- Karl Heinz Buchegger kbuchegg@gascad.at
- Next message: NKOBAYE027: "Re: weird #define statement"
- Previous message: Datta Patil: "Re: How to prevent a class from being inheritable, in C++"
- In reply to: Alberto Barbati: "Re: unpacking ints"
- Next in thread: Alberto Barbati: "Re: unpacking ints"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|
|