[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: [ANN] Lua 5.3.0 (beta) now available
- From: William Ahern <william@...>
- Date: Thu, 23 Oct 2014 17:43:47 -0700
On Thu, Oct 23, 2014 at 03:37:32PM -0700, Coda Highland wrote:
> On Thu, Oct 23, 2014 at 3:17 PM, William Ahern
> <william@25thandclement.com> wrote:
> >> That is, 2^7 +1 is -128 for a "signed char" (or whatever) or it's 129 for
> >> an unsigned char, even though the rvalue's bits are the same...?
> >
> > I think you may have meant -127. But the bits are not necessarily the same.
> > That's only the case in two's complement representation. You have to be
> > careful about differentiating value and representation.[1]
>
> No, he meant -128, the range of a signed byte in two's complement is
> -128 to +127.
>
I think you're missing the +1. 2^7 is 1000000 which is -128 in two's
complement. But 2^7+1 is 10000001 which is -127.
Try running:
#include <stdio.h>
int main(void) {
int i = (1<<7) + 1;
printf("signed:%d unsigned:%d\n", (char)i, (unsigned char)i);
return 0;
}
I get
$ foo
signed:-127 unsigned:129
- References:
- [ANN] Lua 5.3.0 (beta) now available, Luiz Henrique de Figueiredo
- Re: [ANN] Lua 5.3.0 (beta) now available, Paige DePol
- Re: [ANN] Lua 5.3.0 (beta) now available, Luiz Henrique de Figueiredo
- RE: [ANN] Lua 5.3.0 (beta) now available, Newman, Edward (iLO Firmware)
- Re: [ANN] Lua 5.3.0 (beta) now available, Roberto Ierusalimschy
- Re: [ANN] Lua 5.3.0 (beta) now available, Sean Conner
- Re: [ANN] Lua 5.3.0 (beta) now available, Thiago L.
- Re: [ANN] Lua 5.3.0 (beta) now available, Andrew Starks
- Re: [ANN] Lua 5.3.0 (beta) now available, William Ahern
- Re: [ANN] Lua 5.3.0 (beta) now available, Coda Highland