0% found this document useful (0 votes)
391 views9 pages

Data Representation Refers To The Form in Which Data Is Stored, Processed, and Transmitted

This document discusses data representation in computers. It explains that data is stored as binary digits (bits) that can have a value of 0 or 1. A group of 8 bits is called a byte. There are different number systems used in computing including binary, decimal, octal and hexadecimal. Binary uses only 0s and 1s while other systems use additional digits. Unsigned binary integers represent a range of values from 0 to 2^N-1 where N is the number of bits. Signed binary numbers use the most significant bit to indicate sign (0 for positive, 1 for negative) with the remaining bits representing the magnitude. Different methods for representing negative binary numbers include sign-magnitude, one's complement, and two's complement.

Uploaded by

Rafena Mustapha
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
391 views9 pages

Data Representation Refers To The Form in Which Data Is Stored, Processed, and Transmitted

This document discusses data representation in computers. It explains that data is stored as binary digits (bits) that can have a value of 0 or 1. A group of 8 bits is called a byte. There are different number systems used in computing including binary, decimal, octal and hexadecimal. Binary uses only 0s and 1s while other systems use additional digits. Unsigned binary integers represent a range of values from 0 to 2^N-1 where N is the number of bits. Signed binary numbers use the most significant bit to indicate sign (0 for positive, 1 for negative) with the remaining bits representing the magnitude. Different methods for representing negative binary numbers include sign-magnitude, one's complement, and two's complement.

Uploaded by

Rafena Mustapha
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 9

DATA REPRESENTATION IN COMPUTERS

Data Representation refers to the form in which data is stored, processed, and transmitted.
 The 0s and 1s used to represent digital data are referred to as binary digits — from this term we
get the word bit that stands for binary digit.
 A bit is a 0 or 1 used in the digital representation of data.

Bites and Bytes


 All of the data stored and transmitted by digital devices is encoded as bits.
 Terminology related to bits and bytes is extensively used to describe storage capacity and
network access speed.
 The word bit, an abbreviation for binary digit, can be further abbreviated as a lowercase b.
 A group of eight bits is called a byte and is usually abbreviated as an uppercase B.

CAPE Computer Science Unit 1


Number Systems
There are four number systems of possible interest to the computer programmer: decimal, binary,
octal, and hexadecimal.  Each system is characterized by its base or radix, always given in
decimal, and the set of permissible digits.  Note that the hexadecimal numbering system calls for
more than ten digits, so we use the first six letters of the alphabet.

Decimal              Base = 10
                           Digit Set = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9}
Binary                Base = 2
                           Digit Set = {0, 1}
Octal                  Base = 8 = 23
                           Digit Set = {0, 1, 2, 3, 4, 5, 6, 7}
Hexadecimal      Base = 16 = 24
                           Digit Set = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, A, B, C, D, E, F}

CAPE Computer Science Unit 1


The figure below shows the numeric equivalents in binary and decimal of the first 16 hexadecimal
numbers.  The following is taken from that figure.
 
Binary             Decimal                 Hexadecimal
(base 2)            (base 10)                (base 16)
  0000                  00                              0
  0001                  01                              1                    Note that conversions from hexadecimal 
  0010                  02                              2                    to binary can be done one digit at a time,
  0011                  03                              3                    thus DE = 11011110, as D = 1101 and
  0100                  04                              4                    E = 1110.  We shall normally denote
  0101                  05                              5                    this as DE = 1101 1110 with a space
  0110                  06                              6                    to facilitate reading the binary.
  0111                  07                              7
  1000                  08                              8                    Conversion from binary to hexadecimal
  1001                  09                              9                    is also quite easy.  Group the bits four at
  1010                  10                              A                    a time and convert each set of four.
  1011                  11                              B                    Thus 10111101, written 1011 1101 for
  1100                  12                              C                    clarity is BD because 1011 = B and 
  1101                  13                              D                    1101 = D.
  1110                  14                              E
  1111                  15                              F

Unsigned binary integers

An N–bit binary integer can represent one of 2N possible integer values.

In the standard interpretation, always used in this course, an N–bit unsigned integer will represent
2N integer values in the range 0 through 2 N – 1, inclusive.  Sample ranges include:
      N =          4      0 through     24 – 1         0 through                          15
      N =          8      0 through     28 – 1         0 through                        255
      N =        12      0 through    212 – 1         0 through                      4095
      N =        16      0 through    216 – 1         0 through                    65535
      N =        20      0 through    220 – 1         0 through              1,048,575
      N =        32      0 through    232 – 1         0 through       4,294,967,295

Conversions between binary and decimal

Conversion of integers from decimal to binary is done by repeated integer division with keeping of
the integer quotient and noting the integer remainder.  The remainder numbers are then read top to
bottom as least significant bit to most significant bit.  Here is an example.

CAPE Computer Science Unit 1


                           Quotient    Remainder
             23/2 =        11                  1                 Thus decimal 23 = binary 10111
             11/2 =         5                   1
              5/2 =          2                   1                 Remember to read the binary number
              2/2 =          1                   0                 from bottom to top.
              1/2 =          0                   1                 This last step must be done to get the first 1.

The intuitive way to convert decimal 23 to binary is to note that 23 = 16 + 7 = 16 + 4 + 2 + 1.  Thus


decimal 23 = 10111 binary.  As an eight bit binary number this is 0001 0111.  Note that we needed
5 bits to represent the number; this reflects the fact that 2 4 < 23 £ 25.  We expand this to an 8-bit
representation by adding three leading zeroes.

Converting signed numbers to binary

For signed binary numbers the most significant bit (MSB) is used as the sign bit. If the sign bit is
“0”, this means the number is positive in value. If the sign bit is “1”, then the number is negative in
value. The remaining bits in the number are used to represent the magnitude of the binary number
in the usual unsigned binary number format way.
Then we can see that the Sign-and-Magnitude (SM) notation stores positive and negative values by
dividing the “n” total bits into two parts: 1 bit for the sign and n–1 bits for the value which is a pure
binary number. For example, the decimal number 53 can be expressed as an 8-bit signed binary
number as follows:

CAPE Computer Science Unit 1


The disadvantage here is that whereas before we had a full range n-bit unsigned binary number, we
now have an n-1 bit signed binary number giving a reduced range of digits from:
-2(n-1)  to  +2(n-1)

So, for example, if we have 4 bits to represent a signed binary number, (1-bit for the Sign bit and
3-bits for the Magnitude bits), then the actual range of numbers we can represent in sign-
magnitude notation would be:
-2(4-1) – 1    to    +2(4-1) – 1
-2(3) – 1    to    +2(3) – 1
-7    to    +7

Whereas before, the range of an unsigned 4-bit binary number would have been from 0 to 15,
or 0 to F in hexadecimal, we now have a reduced range of -7 to +7. Thus, an unsigned binary
number does not have a single sign-bit, and therefore can have a larger binary range as the most
significant bit (MSB) is just an extra bit or digit rather than a used sign bit.

Another disadvantage here of the sign-magnitude form is that we can have a positive result for
zero, +0 or 00002, and a negative result for zero, -0 or 10002. Both are valid but which one is
correct.

One’s Complement of a Signed Binary Number

One’s Complement or 1’s Complement as it is also termed, is another method which we can use
to represent negative binary numbers in a signed binary number system. In one’s complement,
positive numbers (also known as non-complements) remain unchanged as before with the sign-
magnitude numbers.

Negative numbers, however, are represented by taking the one’s complement (inversion, negation)
of the unsigned positive number. Since positive numbers always start with a “0”, the complement
will always start with a “1” to indicate a negative number.

CAPE Computer Science Unit 1


The one’s complement of a negative binary number is the complement of its positive counterpart,
so to take the one’s complement of a binary number, all we need to do is change each bit in turn.
Thus, the one’s complement of “1” is “0” and vice versa, then the one’s complement
of 100101002 is simply 011010112 as all the 1’s are changed to 0’s and the 0’s to 1’s.

Two’s Complement of a Signed Binary Number


Two’s Complement or 2’s Complement as it is also termed, is another method like the previous
sign-magnitude and one’s complement form, which we can use to represent negative binary
numbers in a signed binary number system. In two’s complement, the positive numbers are exactly
the same as before for unsigned binary numbers. A negative number, however, is represented by a
binary number, which when added to its corresponding positive equivalent results in zero.

In two’s complement form, a negative number is the 2’s complement of its positive number with
the subtraction of two numbers being A – B = A + ( 2’s complement of B ) using much the same
process as before as basically, two’s complement is one’s complement + 1.

The main advantage of two’s complement over the previous one’s complement is that there is no
double-zero problem plus it is a lot easier to generate the two’s complement of a signed binary
number. Therefore, arithmetic operations are relatively easier to perform when the numbers are
represented in the two’s complement format.

Let’s look at the subtraction of our two 8-bit numbers 115 and 27 from above using two’s
complement, and we remember from above that the binary equivalents are:
11510  in binary is:  011100112
2710   in binary is:  000110112

Our numbers are 8-bits long, then there are 28 digits available to represent our values and in binary
this equals: 1000000002 or 25610. Then the two’s complement of 2710 will be:
(28)2 – 00011011 = 100000000 – 00011011 = 111001012

CAPE Computer Science Unit 1


The complementation of the second negative number means that the subtraction becomes a much
easier addition of the two numbers so therefore the sum is: 115 + ( 2’s complement of 27 ) which
is:
01110011 + 11100101 = 1 010110002
As previously, the 9th overflow bit is disregarded as we are only interested in the first 8-bits, so the
result is: 010110002 or (64 + 16 + 8) = 8810 in decimal the same as before.

Representing floating point numbers in binary


Expressing numbers in scientific notation
You may be aware that binary numbers, like decimal numbers, can have decimal points. And that
binary numbers, like decimal numbers, can be expressed using scientific notation:
decimal:  923.52      = 9.2352 x 102
binary:   101011.101  = 1.01011101 x 25
The number that the 10 or 2 is raised to, the “exponent”, represents the number of places shifted to
the left or the right of the decimal point accordingly.
IEEE 754 Representation for binary32
In IEEE 754 floating-point representation, the binary number is divided into three sections: the sign
bit, the exponent and the mantissa (fractional part).

Sign bit
This occupies just one bit and represents the sign: 0 for positive and 1 for negative.
Exponent
The exponent section for a 16-bit (half-precision) floating point occupies 5 bits and stores the
exponent value described above. For 32-bit (single-precision) as in the above binary32 example,
this section occupies 8 bits; for 64-bit (double-precision) formats this section will occupy 11 bits.

CAPE Computer Science Unit 1


Dealing with positive and negative exponents
An 8-bit exponent encoding can represent integers from 0 (00000000) to 255 (11111111). But what
about negative exponents? We need to be able to include these, too. To cover this, we ensure that
the exponent is of value 127 greater. 
If our exponent is (say) 3 then add 127 to it to give 3 + 127 = 130 (decimal) = 10000010 (binary). 
This bias is simply 2n – 1 where n is the number of exponent bits, so 8 bit exponent encodings
would have a bias of 28 – 1 = 128 – 1 = 127.
If our exponent was minus 3, then the outcome would be -3 + 127 = 124 (decimal) = 1111100
(binary). In other words, (00000000) to (01111111) represents the exponents from -127 to zero, and
(10000000) to (11111111) would represent the exponents from +1 to 128.
Mantissa
The third section of our 32-bit representation is 23 bits long. The mantissa, sometimes called the
significand, represents the fractional part of the number in binary scientific notation ie the binary
number to the right of the decimal point.
Example: 12.375 into IEEE 754 binary format
Consider the number 12.375.
Take the non-fractional part of 12.375 and convert it into binary in the normal way:
12 (decimal) is 1100 (binary)
Since 12 = (8 * 1) + (4 * 1) + (2 * 0) + (2 * 0)
Converting the fractional part (0.375) into binary is done using the following procedure:
1. multiply the fraction by 2
2. keep the integer part of multiplication as the binary result
3. re-multiply new fraction by 2
4. repeat 1 – 3 until a fraction of zero is found or until the precision limit is reached which is 23
fraction digits for IEEE 754 binary32 format i.e.:

0.375 x 2  =  0.750   =   0 + 0.750       =>  0


0.750 x 2  =  1.500   =   1 + 0.500       =>  1
0.500 x 2  =  1.000   =   1 + 0.000       =>  1

CAPE Computer Science Unit 1


The fraction part eventually comes to 0.000, so we terminate.  The binary result is 011, therefore
0.375 (decimal) is 0.011 (binary)
So
12.375 (decimal) is now 1100.011 (binary).
Convert result to the required binary scientific format
IEEE 754 binary32 format requires that you represent values in the scientific format described
previously, so that
1100.011  =  1.100011 x 23.
From this scientific notation we can now deduce:
Sign = 0 (positive number)
Exponent = 3
bias = 28-1 = 127  (8-bit exponent encoding for binary32)
adding this to the exponent gives:
3 + 127 = 130 (decimal)  =   10000010 (binary)
Mantissa = 100011 (fractional part to the right of the decimal point)
From these we form the resulting 32 bit IEEE 754 binary32 format representation of 12.375 as:

CAPE Computer Science Unit 1

You might also like