Title: DATA STORAGE
1DATA STORAGE
int temp // How much storage is allocated for
temp? int // How many bits of storage in an
int? // The size of an int is
machine-dependent short int // guaranteed to
be 16 bits ( 2 bytes ) long int // guaranteed
to be 32 bits ( 4 bytes )
2DATA STORAGE
A byte is 8 bits of storage 0000 0000 A
half-byte is called a nybble 0000 A short int
is 16 bits ( 2 bytes ) 0000 0000 0000 0000 A
long int is 32 bits ( 4 bytes ) 0000 0000 0000
0000 0000 0000 0000 0000 Each bit
position has a value. The value is a power of
2 A bit can be on or off, i.e., 0 or
1 There are only two values or "states" for
each bit in binary 0 or 1
3We usually use base 10 or power of 10 in our
everyday life. Consider 125 125 can be
factored this way 1 100 or ( 1
102 ) or 100 2 10 or
( 2 101 ) or 20 5 1 or (
5 100 ) or 5
125 125 in binary can be factored this
way 1 64 or ( 1 26 ) or
64 1 32 or ( 1 25) or
32 1 16 or ( 1 24 ) or 16 1 8 or ( 1
23 ) or 8 1 4 or ( 1 22 ) or
4 0 2 or ( 1 21 ) or 0 1 1 or ( 1
20 ) or 1
125
4Decimal 125 displayed in Binary
0
sign-bit or most significant bit
5 If the data is declared as a short or an int
on a 16-bit machine, then the greatest value that
can be stored in the short or int is 32767.
This is because the high-order or
most-significant-bit cannot be used for data. It
is used to indicate if the data is positive or
negative. It is a sign-bit and is always 1 if
the data is negative. If the data is declared
as an unsigned short or an unsigned int on a
16-bit machine, then the greatest value that can
be stored in the short or int is 65535 or ( 64K -
1 ). This is because the high-order or
most-significant-bit can be used for data. That
bit has a value of 32768. When added to all the
other bits when they are turned on produces a
value of 65535. Remember, a K is NOT 1000!! It
is 1024 or 210.
6To add in binary 5 0000 0000 0000 0101
7 0000 0000 0000 0111 12 0000 0000
0000 1100 8 4
7To subtract in binary 5 0000 0000
0000 0101 - 7 0000 0000 0000 0111
Take the complement of 7 1111 1111 1111
1000 Add 1 to the number 1111 1111 1111
1001 Add that number (-7) 1111 1111 1111
1001 to 5 0000 0000 0000 0101 Result 1111
1111 1111 1110 That is how -2 is stored in
memory.
8To convert back to human-readable form, take the
two's complement and add one to the
result Result 1111 1111 1111
1110 Two's complement of Result 0000 0000
0000 0001 Add 1 0000 0000 0000 0001 Result
is -2 (the system remembers the sign) 0000 0000
0000 0010