Download as pdf or txt
Download as pdf or txt
You are on page 1of 13

9618 – Chapter 1 Notes

1.1 Data Representation

Computers are made up hardware that stores and processes data. If you break a
computer down into its most basic components you have millions of circuits that
either allow electricity to flow, or not. The computer uses electronic circuits to store
one of two values using a switch – the switch is
either ON (1) or OFF (0).

Using a number of these switches provides us with many possible combinations of


1s and 0s which we can use to represent
data values. This is called Binary.

Denary: A system of numbers using ten digits, 0 and 1-9 (also called base-10
system)
Binary: A system of numbers using only 2 bits, 0 and 1 (also called base-2 system)

Binary place values

27 26 25 24 23 22 21 20

Binary to Denary

To convert the binary 111001 into a denary number, use the place values.

Add the place values that are turned ON (1) to get the denary result.
The number is 32+16+8+1 = 57
Denary to Binary
Let’s convert 57 into binary: (Use the same place values.)

• Turn OFF all the place values that are greater than the given number.
(In this case turn OFF 128 and 64)

128 64 32 16 8 4 2 1
0 0

• Turn ON the value that is smaller equal to given value

128 64 32 16 8 4 2 1
0 0 1

• Write a 1 under the column heading 32. That leaves us with 57-32 = 25.
Write a 1 under the column heading 16 (because we can take 16 out of
25. 25-16 leaves 9) You should be able to see now that 9 is an 8 and a 1 so we
end up with:
Always double check by adding the columns up at the end. They should give
you the given number

128 64 32 16 8 4 2 1
0 0 1 1 1 0 0 1

Max and range


They are not the same thing. Consider the following example: If I were
to have 3 binary digits, the maximum value that I could store would be
1112, this equates to 4 + 2 + 1 = 710.If I
were to be asked, the range of numbers Test Yourself
then we have 8 options:
What will be min, max and range
Min 000 of 12 bits?
001 Min:
010
011 Max:
8 set of values - RANGE
100 Range:
101 Formula for Range
110 2𝑛
Max 111 Where n is number of bits
Signed Integer

The pure binary Conversion that we have studied before can only represent positive
integers as the min number that they can represent is 0. And hence it can be used
for unsigned integers. So, how can computer represent negative numbers?

One’s complement and two’s complement are two important binary concepts. Two’s
complement is especially important because it allows us to represent signed
numbers in binary, and one’s complement is the interim step to finding the two’s
complement.

Two’s complement also provides an easier way to subtract numbers using addition
instead of using the longer, more involving subtraction method

One’s Complement
Two’s Complement

The two’s complement is a method for representing positive and negative integer values in binary.
The useful part of two’s complement is that it automatically includes the sign bit.

Finding Two’s Complement of a Denary Value:

Method 1

Positive Integer Negative Integer

Use pure binary conversion add 1 to the one’s complement.

Example: -23 (negative integer)

Step1: Find 23 binary value 00010111


Step 2: invert each bit 11101000
Add these binary values
Step 3: Add +1 to step 2 00000001

11101001  two’s complement value

Method 2: (use and learn this method)

The MSB (the left most bit) still represents a number but is assumed to be
negative. This means that place values, become:

-128 64 32 16 8 4 2 1

-128 64 32 16 8 4 2 1
0 1 1 1 0 1 0 1

28

-128 64 32 16 8 4 2 1
1 0 0 0 1 0 1 1
Two’s Complement Method 2 tips:

When the number is negative always turn ON MSB which has negative place value,
and use this equation

-128 + X = required negative value


Where X represent all the positive place values

Example: -73

-128 64 32 16 8 4 2 1
1

It’s a negative number so X


turn ON -128 (MSB)

-128 + X = -73
X = 128-73
X = 55

-128 64 32 16 8 4 2 1
1 0 1 1 0 1 1 1

55

• In two’s complement the binary value with 0 as MSB is positive value,


and 1 as MSB is negative.

001011 → Positive
100110 → Negative
Twos Complement Binary to Denary

Add all the place values that are turned ON (1)

-128 64 32 16 8 4 2 1
0 1 1 0 0 1 1 0
NOTE: Whenever
64+32+4+2 = 102 MSB is ON the answer
comes as negative
denary value
-128 64 32 16 8 4 2 1
1 0 1 1 0 1 0 1

-128+32+16+4+1 = -75

Two’s Complement Max and Min:

Min for 8-bit -128 64 32 16 8 4 2 1


register: -128 1 0 0 0 0 0 0 0

Max for 8-bit -128 64 32 16 8 4 2 1


register: +127 0 1 1 1 1 1 1 1

Note that the range of possible integers represented by one byte is now -128 to
+127.

Two’s complement has the major advantage that addition and subtraction of two
numbers in two’s complement form produces the correct result – as long as the
result is within the permitted range of possible number of bits.
Binary Addition & Subtraction

The binary number system uses only two digits 0 and 1 due to which their addition
is simple. There are four basic operations for binary addition, as mentioned above.

Carry Sum
0+0 0
0+1 1
1+1 1 0
1+1+1 1 1

The column by column addition of binary is applied below in details.

Overflow:
If the result of an arithmetic operation is to too large (positive or negative) to fit into
the resultant bit-group, then arithmetic overflow occurs

Digital systems usually operate on a fixed number of bits. Addition is said


to overflow if the result is out of range of available bits (too big to fit in the available
bits). A 4-bit number, for example, has the range [0, 15]. 4-bit binary
addition overflows if the result exceeds 15. The fifth bit is discarded, producing an
incorrect result in the remaining four bits. Overflow can be detected by checking
for a carry out of the most significant column.

Compute 11012 + 01012. Does overflow occur?

Solution shows the sum is 100102. This result overflows the range
of a 4-bit binary number. If it must be stored as four bits, the most
significant bit is discarded, leaving the incorrect result of 00102. If
the computation had been done using numbers with five or more
bits, the result 100102 would have been correct.

Overflow bit
Remember: −2n−1 ≤ Two's Complement ≤ 2n−1 − 1

−8 ≤ 4 bit ≤ +7

−128 ≤ 8 bit ≤ +127

If 2 Two's Complement numbers are added, and they both have the same sign
(both positive or both negative), then overflow occurs if and only if the result has the
opposite sign. Overflow never occurs when adding operands with different signs.

i.e. Adding two positive numbers must give a positive result


Adding two negative numbers must give a negative result

Overflow occurs if

• (+A) + (+B) = −C
• (−A) + (−B) = +C

Example: Using 4-bit Two's Complement numbers (−8 ≤ 4 bits ≤ +7)

(−7) 1001
+(−6) 1010
------------
(−13) 1 0011 = 3 Overflow (largest −ve number is −8)

Binary Subtraction

Borrow Method:

Remember 10 in
binary is 2
Twos Complement Method:
NOT means taking
Case1: When binary value is given (like in above figure)
complement
B1 – B2 = B1 + (NOT(B2) +1) /Inverse of each
bit

Solving the same problem using this method

1100–1010
1 1 0 0 + (NOT(1 0 1 0) + 1)
1 1 0 0 + (0 1 0 1 + 1)
1 1 0 0 + (0 1 1 0)

1 1 0 0
+ 0 1 1 0
1 0 0 1 0

Discard this bit

Case2: When denary value is given

D1 – D2 = B1 + (- D2)
Convert -D2 to binary using 2’s complement

55 – 20 = 55 + (-22)
Binary Coded Decimal

Binary Coded Decimal (BCD) is a system of writing


numerals (0-9) in binary using only 4 bits

Denary to BCD:

Each digit is changed into a four-bit binary number that is


then placed after one another in sequence.

For example, to convert 398 into BCD,


we convert the
3 to 0011,
9 to 1001
8 to 1000.
Thus, in BCD, 398 is represented by 001110011000.

BCD to Denary:

Divide the binary pattern in group of 4 bits starting from right hand side

0110 1001 0100

6 9 4

Describe practical applications where BCD is used

Some numbers are not proper numbers because they don’t behave like numbers.
For example, a barcode looks like a number but if the barcode for a chocolate bar
is added to the barcode for a sponge cake the result is meaningless. Values that
are written as a string of digits but do not behave like numbers are often stored in
binary coded decimal (BCD)

BCD code is useful for outputting to displays that are always numeric (0 to 9), such
as those found in digital clocks or digital voltmeters.
Hexadecimal System

Hexadecimal system is base 16 system that was developed for humans, as they
are not very good at remembering long strings of numbers or to say binary values
so, to make it easier for us, we can represent every group of 4 bits with a single
hexadecimal digit.

1 Hex digit = 4 bits = 1 nibble

The smallest value you can have with 4 bits is 0000 = 0.


The largest value is 1111= 15. In base 10 we have 10
symbols 0 to 9, if we use the 16 symbols for 0 to 15 we
can use a system based on place values of 16 rather
than 2 or 10. We call this hexadecimal (or hex for short).
We do, however need to have symbols for the numbers
10, 11, 12, 13, 14 and 15. We use the letters A, B, C, D, E
and F to represent these values.

Binary to Hexadecimal

To convert from Binary to Hex you first need to divide the binary value from right
hand side into group of 4 bits.
Hexadecimal to Binary

Hexadecimal to Denary
Convert Hexadecimal to Binary and Binary to Denary

Denary to Hexadecimal
Convert denary to binary and binary to hexadecimal
Byte: a group of eight bits treated as a single unit
Nibble: a group of four bits.

Decimal Prefix vs Binary Prefix

You might also like