teach-ict.com logo

THE education site for computer science and ICT

2. Unsigned integer

An integer is used to represent a whole number, one that does not have any fractional part.

An unsigned integer makes use of every binary bit to represent a positive number. For example, the unsigned 8 bit binary integer

                          1111 1111

is the equivalent of denary 255.

If the software is only going to deal with positive numbers then this is a very efficient data type to use.

For example, pixel colour can be represented with three positive 8 bit integers - one for Red, one for Green and one for Blue - there are no negative values to be handled.

Many computer languages support two sizes of unsigned integer.

Short unsigned integer

This is 16 bits wide ( 2 bytes) which means it can efficiently handle any positive number up to 216 - 1 which is 65,535. In binary the largest short unsigned integer is

                     1111 1111 1111 1111

In a typical computer language a variable of short integer type may be declared like this

                     MyVariable short int

In many languages, if you declare a general integer type, it assumes you mean short integer, like this

                    MyVariable int

Long unsigned integer

This is 32 bits wide (4 bytes) which means it can handle any positive number up to 4.29 billion or 232 - 1 to be exact. Long unsigned int is suited to handling very large positve whole numbers.

The disadvantage of using long integer is that it consumes 4 bytes of storage, which is wasteful if all the numbers being used are below 65,535.

In a typical computer language, it may be declared like this

                   MyVariable long int

Challenge see if you can find out one extra fact on this topic that we haven't already told you

Click on this link: Short and long integer