Re: integral type conversions

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi Perry,

> If the source is a signed integral type and the destination is an
> unsigned integral type that is larger, are the additional bits done
> via sign extension or zero extension?

On 2's complement machines (the only sort I've ever used), the additional
bits are done via sign extension.

This behavior should be identical to the behavior in C.

Side note: I use the Java convention of converting a char to an int:

char c = '\xAA';
int i;
i = c & 0xFF;

Works the reliably on plain-char-is-signed and plain-char-is-unsigned
machines.  Presuming the architecture is 8-bit-bytes (such as all my
platforms are).  And I'm not sure if there's caveats for 1's complement
machines to worry about.

Sincerely,
--Eljay


[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux