0% found this document useful (0 votes)
7 views13 pages

Binary Numbers and Logic Concepts

This document covers the topic of Numbers and Logic within Computer Systems, focusing on binary numbers, binary arithmetic, and various number systems such as BCD and ASCII. It outlines the learning outcomes for students, including performing operations on binary numbers and understanding truth-tables. Additionally, it explains the significance of binary in computer operations and provides methods for converting between different number systems.

Uploaded by

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

Binary Numbers and Logic Concepts

This document covers the topic of Numbers and Logic within Computer Systems, focusing on binary numbers, binary arithmetic, and various number systems such as BCD and ASCII. It outlines the learning outcomes for students, including performing operations on binary numbers and understanding truth-tables. Additionally, it explains the significance of binary in computer operations and provides methods for converting between different number systems.

Uploaded by

slimemalawi
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Topic X – Topic Title Module Title

Module: Computer Systems


Topic: 6
Title of topic: Numbers and Logic

© NCC Education Limited

Numbers and Logic Topic 6 - 6.2

Scope and Coverage


This topic will cover:
• Binary numbers
• Binary arithmetic and conversion
• Negative binary numbers
• Binary Coded Decimal (BCD)
• ASCII character set
• Logic and truth-tables

Numbers and Logic Topic 6 - 6.3

Learning Outcomes
By the end of this topic students will be able to:
• Perform operations on binary numbers.
• Explain alternative numbering systems (BCD and
ASCII).
• Understand and work with truth-tables and the
associated digital logic circuits.

V0.0 Visuals Handout – Page 1


Topic X – Topic Title Module Title

Numbers and Logic Topic 6 - 6.4

Computer systems - roadmap


In previous topics different computer
systems are introduced. As the focus of
Advanced topics this unit is the digital computer, it is now
Computer networks time to study binary numbers.
Embedded systems
Digital logic
The binary number knowledge will enable
Computer systems software a better understanding of the structure of
Computer programs computer programs and the digital logic
Numbers and logic circuit.
Operating systems 2
Here, the binary number arithmetic, binary
Computer systems hardware
Computer systems
number formats as hexadecimal, ascii,
octal number systems as well as the logic
operators are covered.

Numbers and Logic Topic 6 - 6.5

Numbers and Logic


Computers "understand" only BINARY numbers.
Why is this?
All arithmetic is done in BINARY numbers
All comparisons are done in BINARY numbers
All peripheral transfers are done in BINARY numbers
All programs are stored in BINARY numbers
All data is stored in BINARY numbers
All games are played in BINARY numbers!

Numbers and Logic Topic 6 - 6.6

Numbers and Logic


So, it's important that we can understand the
BINARY numbers and know how to manipulate them
However, we are initially better in understanding the
decimal numbers, so let's look at these first

Consider the following number: 358


What does this number mean? Can you
break it into its constituent parts? Just
think about it; we normally do not as we
take it for granted...

V0.0 Visuals Handout – Page 2


Topic X – Topic Title Module Title

Numbers and Logic Topic 6 - 6.7

Numbers and Logic


Let's consider the decimal number system

3 5 8
Hundreds: Tens: there Ones: there
there are 3 are 5 tens in are 8 ones
hundreds in this position in this
this position position

(3 x 100) + (5 X 10) + (8 X 1) = 358

Numbers and Logic Topic 6 - 6.8

Numbers and Logic


Alternatively, think of it this way

When the ones digit reaches 10 we have a new tens digit, so,
add it to the tens count and set the ones digit to zero. Similarly,
when the tens digit reaches 10 we have a new hundreds digit,
so, add it to the hundreds count and set the tens digit to zero and
so on, i.e. each digit can only be a number between 0 and 9.

We can have ANY numbering system

Consider a numbering system based on a base of 8. That is, it


will have ones, eights, sixty-fours, etc. So, what number will 8-
based number 125 be in the decimal numbering system?

Numbers and Logic Topic 6 - 6.9

Numbers and Logic


Let's consider the 8-based number system

1 2 5
Sixty-fours: Eights: there Ones: there
there is 1 are 2 eights are 5 ones
sixty-fours in in this in this
this position position position

(1 x 64) + (2 X 8) + (5 X 1) = 85 (decimal)

V0.0 Visuals Handout – Page 3


Topic X – Topic Title Module Title

Numbers and Logic Topic 6 - 6.10

Numbers and Logic


Alternatively, think of it this way
When the ones digit reaches 8 we have a new eights digit, so,
add it to the eights count and set the ones digit to zero. Similarly,
when the eights digit reaches 8 we have a new sixty-fours digit,
so, add it to the sixty-fours count and set the eights digit to zero
and so on, i.e. each digit can only be a number between 0 and 7.

So, what about the BINARY number system?

In the binary number system, each digit can only be a 0 (zero) or


a 1 (one). There are ones, twos, fours, eights, etc. digits in a
binary number.

Numbers and Logic Topic 6 - 6.11

Numbers and Logic


Let's consider the 2-based (binary) number system

1 0 1
Fours: there Twos: there Ones: there
is 1 fours in are no twos is 1 ones in
this position in this this position
position

(1 x 4) + (0 X 2) + (1 X 1) = 5 (decimal)

Numbers and Logic Topic 6 - 6.12

Numbers and Logic


Alternatively, think of it this way
When the ones digit reaches 2 we have a new twos digit, so,
add it to the twos count and set the ones digit to zero. Similarly,
when the twos digit reaches 2 we have a new fours digit, so, add
it to the fours count and set the twos digit to zero and so on, i.e.
each digit can only be a number between 0 and 1.

Here is an example of a binary 0 0 0 1 0 0


count starting from 0. Binary 0 0 1 1 0 1
count increments by one, i.e. 0 1 0 1 1 0
adding a one to the previous 0 1 1 1 1 1
number.

V0.0 Visuals Handout – Page 4


Topic X – Topic Title Module Title

Numbers and Logic Topic 6 - 6.13

Numbers and Logic


Let's have some examples using binary numbers
Converting unsigned binary numbers to decimal numbers
16 8 4 2 1 binary digit weightings

A tip: Wherever there is


1 0 1 1 0 = 22
a 1 in the binary number,
1 1 0 0 0 = 24 add the corresponding
1 1 1 1 1 = 31 digit weighting to the
0 1 0 1 0 = 10 total. Ignore the digits
with a 0.
1 0 0 0 0 = 16

What about converting from decimal to binary?

Numbers and Logic Topic 6 - 6.14

Numbers and Logic


What about converting from decimal to binary?
There are at least two possibilities

Guess (requires some experience)


Repeated division by 2

Guessing is quick for relatively small numbers. For this, just


visualise the binary digit weightings shown in a previous slide.
Repeated division by 2 is slower but easier if converting a largish
decimal number to binary. In fact, this method can be expressed
as an algorithm and coded in a programming language.

Numbers and Logic Topic 6 - 6.15

Numbers and Logic


Conversion from decimal to binary number

Divide the decimal number by 2. Then divide each new result by


2 repeatedly until the final result is less than 2, i.e. 1 or 0. The
remainders obtained during each successive divide constitute
the converted binary number. Have a look at the example below.

2) 50
2) 25 r = 0
2) 12 r = 1
2) 6 r = 0 Result = 1 1 0 0 1 0
2) 3 r = 0
2) 1 r = 1
0 r = 1

V0.0 Visuals Handout – Page 5


Topic X – Topic Title Module Title

Numbers and Logic Topic 6 - 6.16

Binary number arithmetic


Now, let’s do some binary arithmetic
Adding binary numbers Subtracting binary numbers
0 1 1 0 1 1 = 27 0 1 1 0 1 1 = 27
+ 0 1 0 0 1 0 = 18 - 0 0 0 1 1 0 = 6
1 0 1 1 0 1 = 45 0 1 0 1 0 1 = 21
Multiplying binary numbers
0 1 1 0 1 1 = 27
x 1 0 1 = 5
0 1 1 0 1 1
0 0 0 0 0 0
+0 1 1 0 1 1
1 0 0 0 0 1 1 1 = 135

Numbers and Logic Topic 6 - 6.17

Negative binary numbers


Computers do not subtract; they negate the 2's complement
of the second number and add. Effectively, this is the same
as subtraction. This enables the computer to do arithmetic.
Negating 2's complement of a binary number is done by
complementing all the bits and adding 1. A binary number is
complemented by changing all 0's to 1's and all 1's to 0's:
1 0 1 1 0 0 1 0 when complemented becomes 0 1 0 0 1 1 0 1
1 0 1 1 0 1 0 0 -76 00100000 32
Here are some 01001011 11011111
examples: +1 +1
0 1 0 0 1 1 0 0 76 11100000 -32

Numbers and Logic Topic 6 - 6.18

Negative binary numbers


Here are some more examples:
Negative binary numbers Negative binary numbers
0 1 0 0 1 0 = 18 0 0 1 0 0 1 = 9
- 0 1 1 0 1 1 = 27
1 1 0 1 1 1 =- 9 1 1 0 1 1 0 = ~9
+ 0 0 1 0 0 1 = 9 + 0 0 0 0 0 1 = 1
0 0 0 0 0 0 = 0 1 1 0 1 1 1 =- 9
- 0 0 1 0 0 1 = 9
1 1 0 1 1 1 =- 9
Two’s complement method: To negate a binary
number, first reverse all its bits, i.e. 0's become 1's and
1's become 0's, then add a 1 to it.

V0.0 Visuals Handout – Page 6


Topic X – Topic Title Module Title

Numbers and Logic Topic 6 - 6.19

Negative binary numbers


Two's complement numbers are simply numbers in which
the high order bit position is assigned a negative positional
value.
For example, in an 8-bit 2's complement number, the high
order bit has a positional value of -128 rather than 128:

-128 64 32 16 8 4 2 1
0 1 1 1 0 1 0 1 = 64 + 32 + 16 + 4 + 1 = 117
-128 64 32 16 8 4 2 1
1 1 1 1 0 1 0 1 = -128 + 64 + 32 + 16 + 4 + 1 = - 11

Numbers and Logic Topic 6 - 6.20

Negative binary numbers


Converting negative binary numbers to decimal
In two’s complement format, the negative
numbers contain a 1 in the most significant digit
position. For example:

1 0 0 1 1 0 1 1

-128 +27 = -121

Numbers and Logic Topic 6 - 6.21

Binary number formats


How binary numbers are stored in memory

0 1 1 0 0 1 0 1 0 1 1 1 0 0 1 0

nibble = 4 bits

byte = 8 bits
word = 16 bits
It can also be 32, 64 or A 16-bit word is 2 bytes
more bits depending on the A 32-bit word is 4 bytes
type of the computer. A byte is 2 nibbles

V0.0 Visuals Handout – Page 7


Topic X – Topic Title Module Title

Numbers and Logic Topic 6 - 6.22

Octal and hexadecimal numbers


Octal and Hexadecimal numbers
Octal numbers are 3 bits in length per octal digit
0 1 1 0 1 1 0 1 0 1 1 1 1 0 1 0 = 0665728

Hexadecimal numbers are 4 bits in length per Hex digit


0 1 1 0 1 1 0 1 0 1 1 1 1 0 1 0 = 6D7A16

Hex digits are 0 - 9, A(10), B(11), C(12), D(13), E(14), F(15)

Can you convert the following hex numbers to decimal


numbers? Hex 2FA, Hex A5, Hex 001C

Numbers and Logic Topic 6 - 6.23

Binary coded decimal numbers


BCD is a representation of decimal numbers in
binary form. In this format, each decimal digit is
converted to its 4-bit (or nibble) binary equivalent.
For example:
5 7

0101 0111
5710 = 0101 0111bcd
5710 = 0011 1001bin = 39hex

Numbers and Logic Topic 6 - 6.24

Adding BCD numbers


6 0 1 1 0 BCD for 6 42 0 1 0 0 0 0 1 0 BCD for 42
+3 0 0 1 1 BCD for 3 +27 0 0 1 0 0 1 1 1 BCD for 27
1 0 0 1 BCD for 9 0 1 1 0 1 0 0 1 BCD for 69

Where the result of any addition exceeds 9 (1001) then 6


(0110) must be added to the sum to account for the six
disallowed BCD codes (from 10 to 15);

8 1 0 0 0 BCD for 8 1111


+7 0 1 1 1 BCD for 7 +6 0 1 1 0 BCD for 6
1111 0 0 0 1 0 1 0 1 BCD for 15

V0.0 Visuals Handout – Page 8


Topic X – Topic Title Module Title

Numbers and Logic Topic 6 - 6.25

Using BCD numbers – an example


A 7-segment display
Look-up Table
8 3 5 10

0123456 1000 0011 0101


3 1011011

5 1101011

8 1111111

Numbers and Logic Topic 6 - 6.26

ASCII character set


Each printable character is assigned an ASCII code. This
code is used by peripherals capable of reading (e.g keyboard)
characters, displaying characters and printing characters to
determine what character is being processed. They use a
look-up table of ASCII characters stored in memory.

Char Hex Dec Char Hex Dec Char Hex Dec

'0' 30 48 'A' 41 65 'a' 61 97

'1' 31 49 'B' 42 66 'b' 62 98

'2' 32 50 'C' 43 67 'c' 63 99

Numbers and Logic Topic 6 - 6.27

Using ASCII characters – an


example
Hex Char
48656C6C6F
48 'H'
Memory
65 'e'

6C 'l'
Printer
Look-up
Table

Display Hello

V0.0 Visuals Handout – Page 9


Topic X – Topic Title Module Title

Numbers and Logic Topic 6 - 6.28

ASCII vs. Unicode characters


Standard ASCII characters are 7-bit long allowing the
specification of 127 characters. Extended ASCII adds
another 127 characters. ASCII was primarily developed
for English letters, numbers and symbols.
Unicode characters are 16-bit long allowing many more
characters to be specified than ASCII and can represent
characters from:
• Multiple languages
• Multiple scripts
• Mathematical symbols
• Specialised characters

Numbers and Logic Topic 6 - 6.29

Logic and truth tables


In computer logic there are only two values: True and False

These can be represented by any two numbers. However, it


is customary to represent True by number 1 and False by
number 0. This fits in well with the binary nature of the
computer world: TRUE = 1 and FALSE = 0.

Logical relationships between these two logic values are


established by the logical operators AND, OR and NOT
according to the rules of logic defined in truth-tables. These
logical operators are fundamental to the construction of both
computer hardware (using logic gates) and software (using
logical operators in programming languages).
2 March 2008 CIS1000 (Number and Logic 2): Session 5b 29

Numbers and Logic Topic 6 - 6.30

Logic and truth tables


AND truth-table OR truth-table NOT truth-table

False False False False False False False True

False True False False True True True False

True False False True False True

True True True True True True

10110100 10110100 10110100


1 1 0 0 1 1 1 0 AND 1 1 0 0 1 1 1 0 OR NOT
10000100 11111110 01001011

V0.0 Visuals Handout – Page 10


Topic X – Topic Title Module Title

Numbers and Logic Topic 6 - 6.31

AND logic example


Logic in real life - both are required!
valve valve flow
water A B

Shut Shut False


valve A
Shut Open False

Open Shut False


valve B
Open Open True

flow

Numbers and Logic Topic 6 - 6.32

OR logic example
Logic in real life - either will do!
water
valve valve flow
A B

valve A valve B Shut Shut False

Shut Open True

Open Shut True

flow Open Open True

Numbers and Logic Topic 6 - 6.33

NOT logic example


Logic in real life – LED night light with auto sensor
light

light glow

On Off

Off On
glow

V0.0 Visuals Handout – Page 11


Topic X – Topic Title Module Title

Numbers and Logic Topic 6 - 6.34

Quiz
1. Explain why binary numbers are important for digital
computers?
2. List the valid numbers for octal (base 8) numbering system.
3. Explain how a negative binary number differs from a positive
binary number in signed binary numbers.
4. Describe how decimal number can be converted to
hexadecimal number.
5. Add two BCD numbers 7 and 5.
6. If the ASCII code for letter 'i' is 69, state the ASCII code for
'n'.
7. If A is True what is NOT (A AND False)?
8. Explain what a truth table is.

Numbers and Logic Topic 6 - 6.35

Topic Summary
Digital computers process binary numbers. All calculations
and logical operations are carried out using binary
numbers.
Knowledge of binary numbers such as conversions from/to
binary numbers, binary arithmetic and logical operations on
binary numbers, as well as the encoding of binary numbers
in hexadecimal, octal, ascii/Unicode formats is important.
The digital computer functions using logic circuits depend
on understanding of three basic logic operators AND, OR
and NOT, implemented as logic gates, and based on their
associated truth tables.

Numbers and Logic Topic 6 - 6.36

References
 Null, L. and Lobur, J. (2014) The Essentials of
Computer Organization and Architecture. Fourth
edition. Jones and Bartlett Publishers, Inc.
 Englander, I. (2014) The Architecture of Computer
Hardware and Systems Software. 5th Edition. John
Wiley.
 Comer, D. (2017) Essentials of Computer
Architecture. 2nd edition. CRC Press.

V0.0 Visuals Handout – Page 12


Topic X – Topic Title Module Title

Topic 6 – Numbers and Logic

Any Questions?

V0.0 Visuals Handout – Page 13

You might also like