INTEGER NUMBERS IN 2-COMPLEMENT

by:   J.H.M. Bonten


First date of publication: 05 october 2006
Date of modification: 15 january 2007
Date of modification: 25 september 2007
Tiny updates: 21 november 2008

Machines

   IEEE-754 and IBM-360 and DEC-PDP11 pedigree
Also described:
   Unsigned integer and Microsoft Currency

Contents

Back to index of numeric formats


SIGNED INTEGER

The machines that use the IEEE-754 or DEC-floats all use the same notation for the signed-integer values. The negative values are in two-complement notation. Herein the range of negative values exceeds the range of positive values by one. There is only one bit pattern to represent the zero value: 000... (all bits zero). There is not a signed zero (+0,-0).  Also absent are the special values like NaN and Infinity, since there is no value space for them. All available bit patterns are used by the ordinary values.

The signed integers are available in four lengthes. Note there is no medium length. Parentheses in the table below indicate how it might be. The table also shows the maximum number of digits that can be represented by each length of integer. It is based on the maximum value that can be stored in that integer, and equals  10_log (max_value).  The listing is:

length   #bytes #bits  min.neg.value  max.pos.value  #dec.digs

byte,char    1     8       -128           +127           2.1
short        2    16      -32768         +32767          4.5
( medium     3    24     -8388608       +8388607         6.9 )
long         4    32    -2147483648    +2147483647       9.3
36bit(PDP10) 4.5  36   -34359738368   +34359738367      10.5
double-long  8    64     see below      see below       18.9

   double-long min.neg.value = -9 223 372 036 854 775 808
   double-long max.pos.value = +9 223 372 036 854 775 807

Only for the sake of completeness the 36 bits words are added to this list. These words were used in several older computers, e.g. the Digital PDP-10.

In some systems and programming languages the generic word 'Integer' means 'Short-Integer', and in other systems it means 'Long-Integer'. For example: In the DEC-PDP11 it is Short, in C/C++ it is Long. Java's Long is actually double-long. To be certain always use a name with a length specifier in it.

The names with the length-name, with the number of bytes and with the number of bits are used intermixedly. In listing:

C/C++         Java        DEC           Microsoft
-----         ----        ---           ---------
char          byte        byte           __int8
short int     short      integer*2       __int16
long int      int        integer*4       __int32
  --          long       integer*8       __int64

Back to contents


UNSIGNED INTEGER

Some computer systems also use four unsigned integer values. These are never negative. Note also here is no medium length. Parentheses indicate how it might be. The listing is:

length   #bytes #bits  maximum value  minimum value  #dec.digs

byte,char    1     8       +255               0          2.4
short        2    16      +65535              0          4.8
( medium     3    24     +16777215            0          7.2 )
long         4    32    +4294967295           0          9.6
double-long  8    64  +18446744073709551615   0         19.2

The set of names for these data types is fairly small, not far more than indications like: 'unsigned char', 'unsigned short' and 'unsigned long int'. The unsigned double-long is used by DEC-VAX and DEC-Alpha only. It is not available on the PC.

Back to contents


MICROSOFT CURRENCY

Microsoft says: A currency number is stored as an 8-byte two's complement integer, scaled by 10000 to give a fixed-point number with 15 digits to the left of the decimal point and 4 digits to the right. This representation provides a range of 922337203685477.5807 to -922337203685477.5808. The CURRENCY data type is useful for calculations involving money, or for any fixed-point calculation where accuracy is particularly important.

Back to contents


LINKS

Various manuals and handbooks, e.g:
Digital:
   PDP-11 processor handbook + Fortran language reference manual
   VAX Fortran language reference manual
   Alpha Architecture handbook
Hewlett-Packard:
   HP-UX Fortran language manual, for HP-9000 series 300 or 500
Microsoft library: Currency

Back to contents

Back to index of numeric formats