computer science lab#2
CS 1150 – Lab #2 – Exploring Number Systems
TAs – Soumya Chiday, [email protected]
Sri Ram Srujan Yidala, [email protected]
1
TA Labs, Office Hours Laboratory Polices
Lab Hours
CS 1150 L 05 T 11:00 am – 12:50 pm – 320 Oelman
CS 1150 L 06 R 11:00 am – 12:50 pm – 320 Oelman
TA Office Hours
1:00 PM – 2:00 PM, Tuesday/Thursday at Room 316 - Russ Engineer Center
By appointment – Please email to [email protected] or [email protected]
Refer to CS 1150 Course Syllabus for Class and Laboratory Policies
Zero tolerance policy for Academic Misconduct – All parties will get 0% marks
CS 1150 - Lab 2 - Exploring Number Systems
2
Lab # 2 Overview
Experiment with Number Systems
Different Number Systems
Decimal/Binary/Octal/Hexadecimal
Conversions
Binary Arithmetic
Lab #2 Due Date - September 21, 2018 11:55 PM
CS 1150 - Lab 2 - Exploring Number Systems
3
How to Submit Lab # 2
Soft copy
Go to Pilot Course Page and Use the Dropbox Submission Link to upload your files
CS 1150 - Lab 2 - Exploring Number Systems
4
Number Systems
Four number system
Decimal (10)
Binary (2)
Octal (8)
Hexadecimal (16)
CS 1150 - Lab 2 - Exploring Number Systems
5
Decimal System
A decimal number is a sequence of digits
Decimal digits must be in the set: {0, 1, 2, 3, 4, 5, 6, 7, 8, 9} (Base 10)
Position weights are powers of 10
The weight of the rightmost (least significant digit) is 100 (i.e.1)
CS 1150 - Lab 2 - Exploring Number Systems
6
Decimal Numbers
1439 = 1 x 103 + 4 x 102 + 3 x 101 + 9 x 100
Thousands Hundreds Tens Ones
Radix = 10
CS 1150 - Lab 2 - Exploring Number Systems
7
Binary System
So in a computer, the only possible digits we can use to encode data are {0,1}
The numbering system that uses this set of digits is the base 2 system (also called the Binary Numbering System)
We can apply all the principles of the base 10 system to the base 2 system
Position weights are powers of 2
CS 1150 - Lab 2 - Exploring Number Systems
8
Binary Decimal
1101 = 1 x 23 + 1 x 22 + 0 x 21 + 1 x 20
= 1 x 8 + 1 x 4 + 0 x 2 + 1 x 1
= 8 + 4 + 0 + 1
(1101)2 = (13)10
1, 2, 4, 8, 16, 32, 64, 128, 256, 512, ….
CS 1150 - Lab 2 - Exploring Number Systems
9
CS 1150 - Lab 2 - Exploring Number Systems
10
Octal Decimal
137 = 1 x 82 + 3 x 81 + 7 x 80
= 1 x 64 + 3 x 8 + 7 x 1
= 64 + 24 + 7
(137)8 = (95)10
Digits used in Octal number system – 0 to 7
CS 1150 - Lab 2 - Exploring Number Systems
11
CS 1150 - Lab 2 - Exploring Number Systems
12
Hex Decimal
BAD = 11 x 162 + 10 x 161 + 13 x 160
= 11 x 256 + 10 x 16 + 13 x 1
= 2816 + 160 + 13
(BAD)16 = (2989)10
A = 10, B = 11, C = 12, D = 13, E = 14, F = 15
CS 1150 - Lab 2 - Exploring Number Systems
13
CS 1150 - Lab 2 - Exploring Number Systems
14
Conversions from Binary to Oct and Hex
Three bits make one octal digit
111 010 110 101
7 2 6 5 => 7265 in octal
Four bits make one hexadecimal digit
1110 1011 0101
E B 5 => EB5 in hex
CS 1150 - Lab 2 - Exploring Number Systems
15
Why to learn these number systems?
Longer binary numbers are what computers use at the hardware level. However, they can be very difficult to parse by a human being. This is the reason for using octal, and more frequently hexadecimal. Converting from these bases to binary is trivial, but the numerals themselves will be human readable. It's for communication between programmers/architects and these machines we build.
CS 1150 - Lab 2 - Exploring Number Systems
16
Lab # 2 Question 7
CS 1150 - Lab 2 - Exploring Number Systems
17
1 + 1 in Binary is 0 with a Carry 1
Source – CS 1150 Chapter Two Slides by Karen Meyer
Lab #2 Question 5 and 6
CS 1150 - Lab 2 - Exploring Number Systems
18
Lab #2 Question 8 and 9
CS 1150 - Lab 2 - Exploring Number Systems
19
Lab # 2 Question 9 Hint
CS 1150 - Lab 2 - Exploring Number Systems
20
Questions ?
If you have questions, please raise your hand.
CS 1150 - Lab 2 - Exploring Number Systems
21