Logic 1

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

Digital Computer Systems

• Digital systems consider discrete amounts of data.


• Examples
– 26 letters in the alphabet
– 10 decimal digits
• Larger quantities can be built from discrete values:
– Words made of letters
– Numbers made of decimal digits (e.g. 239875.32)
• Computers operate on binary values (0 and 1)
• Easy to represent binary values electrically
– Voltages and currents.
– Can be implemented using circuits
– Create the building blocks of modern computers

Logic Circuits -Dr. Mohamad Alwan 1

Understanding Decimal Numbers

• Decimal numbers are made of decimal digits: (0,1,2,3,4,5,6,7,8,9)


• Decimal number:
– 8653 = 8x103 + 6x102 + 5x101 + 3x100
• What about fractions?
– 97654.35 = 9x104 + 7x103 + 6x102 + 5x101 + 4x100 + 3x10-1 + 5x10-2
– In formal notation -> (97654.35)10
• Why do we use 10 digits, anyway?

Logic Circuits -Dr. Mohamad Alwan 2

1
Understanding Binary Numbers

• Binary numbers are made of binary digits (bits):


– 0 and 1
• binary number:
– (1011)2 = 1x23 + 0x22 + 1x21 + 1x20 = (11)10
• What about fractions?
– (110.10)2 = 1x22 + 1x21 + 0x20 + 1x2-1 + 0x2-2
• Groups of eight bits are called a byte
– (11001001) 2
• Groups of four bits are called a nibble.
– (1101) 2

Logic Circuits -Dr. Mohamad Alwan 3

Conversion Between Number Bases

Decimal(base 10) Binary(base 2)

Hexadecimal
(base16)
° Learn to convert between bases.

Logic Circuits -Dr. Mohamad Alwan 4

2
Decimal review
• Numbers consist of a bunch of digits, each with a weight

1 6 2 . 3 7 5 Digits
100 10 1 1/10 1/100 1/1000 Weights

• These weights are all powers of the base, which is 10. We can rewrite
this:
1 6 2 . 3 7 5 Digits
102 101 100 10-1 10-2 10-3 Weights

• To find the decimal value of a number, multiply each digit by its weight
and sum the products.

(1 x 102) + (6 x 101) + (2 x 100) + (3 x 10-1) + (7 x 10-2) + (5 x 10-3) = 162.375

Logic Circuits -Dr. Mohamad Alwan 5

Converting binary to decimal


• We can use the same trick to convert binary, or base 2, numbers to
decimal. This time, the weights are powers of 2.
– Example: 1101.01 in binary
1 1 0 1 . 0 1 Binary digits, or bits
23 22 21 20 2-1 2-2 Weights (in base 10)

– The decimal value is:

(1 x 23) + (1 x 22) + (0 x 21) + (1 x 20) + (0 x 2-1) + (1 x 2-2) =


8 + 4 + 0 + 1 + 0 + 0.25 = 13.25

Powers of 2: Useful abbreviations:


20 = 1 24 = 16 28 = 256 K = 210 = 1,024
1
2 =2 25 = 32 29 = 512 M = 220 = 1,048,576
22 = 4 26 = 64 210 = 1024 G = 230 = 1,073,741,824
3
2 =8 27 = 128

Logic Circuits -Dr. Mohamad Alwan 6

3
Converting decimal to binary
• To convert a decimal integer into binary, keep dividing by 2 until the
quotient is 0. Collect the remainders in reverse order.
• To convert a fraction, keep multiplying the fractional part by 2 until it
becomes 0. Collect the integer parts in forward order.
• Example: 162.375:

162 / 2 = 81 rem 0 0.375 x 2 = 0.750


81 / 2 = 40 rem 1 0.750 x 2 = 1.500
40 / 2 = 20 rem 0 0.500 x 2 = 1.000
20 / 2 = 10 rem 0
10 / 2 =5 rem 0
5/2 =2 rem 1
2/2 =1 rem 0
1/2 =0 rem 1

• So, 162.37510 = 10100010.0112

Logic Circuits -Dr. Mohamad Alwan 7

Base 16 is useful too


• The hexadecimal system uses 16 digits:
Decimal Binary Hex
0123456789ABCDEF 0 0000 0
• You can convert between base 10 and base 1 0001 1
16 using techniques like the ones we just 2 0010 2
showed for converting between decimal and 3 0011 3
binary. 4 0100 4
5 0101 5
• For our purposes, base 16 is most useful as
6 0110 6
a “shorthand” notation for binary numbers.
7 0111 7
– Since 16 = 24, one hexadecimal digit is 8 1000 8
equivalent to 4 binary digits. 9 1001 9
– It’s often easier to work with a number 10 1010 A
like B4 instead of 1011 0100. 11 1011 B
12 1100 C
13 1101 D
14 1110 E
15 1111 F

Logic Circuits -Dr. Mohamad Alwan 8

4
Binary and hexadecimal conversions
• Converting from hexadecimal to binary is easy: just replace each hex
digit with its equivalent 4-bit binary sequence.

261.3516 = 2 6 1 . 3 516
= 0010 0110 0001 . 0011 01012

• To convert from binary to hex, make groups of 4 bits, starting from the
binary point. Add 0s to the ends of the number if needed. Then, just
convert each bit group to its corresponding hex digit.

10110100.0010112 = 1011 0100 . 0010 11002


= B 4 . 2 C16

Hex Binary Hex Binary Hex Binary Hex Binary


0 0000 4 0100 8 1000 C 1100
1 0001 5 0101 9 1001 D 1101
2 0010 6 0110 A 1010 E 1110
3 0011 7 0111 B 1011 F 1111

Logic Circuits -Dr. Mohamad Alwan 9

Hex to Decimal

This time, the weights are powers of 16.


8 7 C 9 =8 x 163+7 x 162+C x 161+9 x 160=34 761

8 7 C 9
x 16
128
+ 7
135
x 16
2,160
+ 12
2,172
x 16
34,752
+ 9
34,761Logic Circuits -Dr. Mohamad Alwan
10

5
Convert Decimal to Hex

Integer Part: Divide by the base,


keep track of the remainder, and read up.
16 34,761
16 2,172 rem 9
16 135 rem 12 = C Read up
16 8 rem 7
0 rem 8

34,76110 = 87C916

Logic Circuits -Dr. Mohamad Alwan 11

Questions

100101012 = ? (decimal)

Logic Circuits -Dr. Mohamad Alwan 12

6
Questions

100101012 = ? (decimal)
1 0 0 1 0 1 0 1
27 26 25 24 23 22 21 20

The decimal Value:

(1 x 27) + (0 x 26) + (0 x 25) + (1 x 24) + (0 x 23) + (1 x 22) + (0 x 21) + (1 x 20) =


128 + 0 + 0 + 16 + 0 + 4 + 0 + 1 =

(149)10

Logic Circuits -Dr. Mohamad Alwan 13

Questions

85710 = ?16

Logic Circuits -Dr. Mohamad Alwan 14

7
Questions

BED16 = ?2

Logic Circuits -Dr. Mohamad Alwan 15

Logic Circuits -Dr. Mohamad Alwan 16

8
Logic Circuits -Dr. Mohamad Alwan 17

Logic Circuits -Dr. Mohamad Alwan 18

9
Exercise 1:
Convert these decimal numbers: 17.76 - 1958.56
- To binary
- To octal (directly from decimal)
- To hexadecimal (directly from decimal)
- To octal (from binary)
- To hexadecimal (from binary)

Exercise 2:
Find the decimal numerical values of:
- The binary numbers: 1101.1 - 101.0101 - 110101.101
- The octal numbers: 236 - 702.41 - 1011.1
- The hexadecimal numbers: A0B.5 – 1011.1 - FC3.0E

Logic Circuits -Dr. Mohamad Alwan 19

10

You might also like