Lecturer: Santokh Singh CompSci 105 SS 2005 Principles of Computer Science Lecture 2 Lecturer: Santokh Singh
Numbers in the Computer Binary representation of integers Octal representation of integers Hexadecimal representation of integers Binary Arithmetic Addition Subtraction Using Bits as Bits Logical Operations
Positive Integers In the range 0-3 …. 11 00 01 10
Decimal Numbers 2 1 7 3
Decimal Numbers 1000 100 10 1 2 1 7 3
Decimal Numbers 103 102 101 100 2 1 7 3
Binary Numbers 1 1 1
Binary Numbers 23 22 21 20 1 1 1
Binary Numbers 8 4 2 1 1 1 1
Exercise Convert the binary number 11010 to decimal
Converting to Binary 1011 11 ? 1011 11
Digit Manipulation Removing the last digit of a number Extracting the last digit of a number 2173 217 ? 2173 3 ?
Extract in Right to Left Order 2173
Converting to Binary Repeat until number is empty Extract last binary digit Remove last binary digit
Exercise Convert the decimal number 77 to binary
Numbers in the Computer Binary representation of integers Octal representation of integers Hexadecimal representation of integers Binary Arithmetic Addition Subtraction Using Bits as Bits Logical Operations
1 5 + 6 1 2 + 3 8 7 + 15 1 + 2 6 4 + 10 2 3 + 5 9 + 18 3 7 + 10 1 +
1 1 + + 1 + + 1 1 1 10
1 1 1 + 1 1 1
1 1 1 - 1 1
Exercises Perform the following binary calculations. Convert to base 10 to check your answer: 101110 +111111 101110 - 11111
If binary is so much easier, why do we use base 10 for most things?
If binary is so much easier, why do we use base 10 for most things? 275 100010011
Numbers in the Computer Binary representation of integers Octal representation of integers Hexadecimal representation of integers Binary Arithmetic Addition Subtraction Using Bits as Bits Logical Operations
Octal 1 2 3 000 001 010 011 4 5 6 7 100 101 110 111
1 0 1 0 1
1 7 3
Hexadecimal 0001 1 0010 2 0000 0011 3 0101 5 0110 6 0100 4 0111 7 1001 9 1010 A 1000 8 1011 B 1101 D 1110 E 1100 C 1111 F
Hex Numbers and Bytes 1000 1011 0010 0011
Course Book Notes for 1st and 2nd lecture:- Pages 62 - 64: Numbers in the Computer Pages 65 - 92: Data Representations