Re: Bit Pattern Problem
From: Alex Fraser (me_at_privacy.net)
Date: 09/02/04
- Next message: pete: "Re: One-past-end-of-object pointers"
- Previous message: pete: "Re: integer array"
- In reply to: pete: "Re: Bit Pattern Problem"
- Next in thread: Barry Schwarz: "Re: Bit Pattern Problem"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Thu, 2 Sep 2004 11:17:18 +0100
"pete" <pfiland@mindspring.com> wrote in message
news:4136EAC9.3A5C@mindspring.com...
> William L. Bahn wrote:
>
> > As assignments between signed and unsigned data types of the same
> > basic type required to copy the bit pattern if the value in the
> > expression can't be represented in the type of the object being
> > assigned to? Or is this undefined behavior?
>
> Assigning an out of range value to a signed integer,
> is implementation defined.
> To assign a negative value to an unsigned,
> (UINT_MAX + 1) is added to the value until it becomes non negative.
(or, obviously, ULONG_MAX + 1 etc, according to the type of the object being
assigned to.)
...which, if the negative value can be represented using two's complement in
the number of value bits in the unsigned integer, leaves the unsigned
integer with the two's complement representation of the negative value.
In many cases this means that assignment of a signed integer type to the
corresponding unsigned integer type does indeed simply copy the bit pattern.
> To assign an out of range positive value to an unsigned,
> (UINT_MAX + 1) is subtracted until the value is in range.
Alex
- Next message: pete: "Re: One-past-end-of-object pointers"
- Previous message: pete: "Re: integer array"
- In reply to: pete: "Re: Bit Pattern Problem"
- Next in thread: Barry Schwarz: "Re: Bit Pattern Problem"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|
|