Hi:

On 23 Dec 2011, at 12:49, Stéphane Ducasse wrote:

> I read somewhere that in C short int range value are  -32767 to +32767
> 
> http://www.ericgiguere.com/articles/ansi-c-summary.html
> 
> And I was wondering why it does not follow the  $-1 * 2^{N-1}\ to\ 2^{N-1}-1$ 
> range encoding

Because your source has a typo?

Have a look into /usr/include/stdint.h that is what runs on your system...

#define INT16_MAX        32767
#define INT16_MIN         -32768


>> 
>> Now I have three questions:
>>      - is two complement used to manage small integers at VM level?
It is done at the hardware level.

Since C does not specify many things including signed overflows, I would assume 
they just map directly onto what the hardware provides.

And for all practical purposes, two's complement is the standard. I am not 
aware of anything mainstream using one's complement. 


>> Now doing 5 - 15 does not (or I miss something ilke always subtracting the 
>> smaller one and taking the two complement of the smaller…)
>>      so does anybody has the answer on how to perform 5 - 15 ?

http://en.wikipedia.org/wiki/Two%27s_complement#Subtraction

Regards
Stefan




-- 
Stefan Marr
Software Languages Lab
Vrije Universiteit Brussel
Pleinlaan 2 / B-1050 Brussels / Belgium
http://soft.vub.ac.be/~smarr
Phone: +32 2 629 2974
Fax:   +32 2 629 3525


Reply via email to