Upload
megan-kerr
View
33
Download
2
Embed Size (px)
DESCRIPTION
Agenda. Shortcuts converting among numbering systems Binary to Hex / Hex to Binary Binary to Octal / Octal to Binary Signed and unsigned binary numbers Addition / Subtraction of Binary Numbers Two’s Complement. Numbering System Shortcuts. - PowerPoint PPT Presentation
Citation preview
Agenda
• Shortcuts converting among numbering systems– Binary to Hex / Hex to Binary– Binary to Octal / Octal to Binary
• Signed and unsigned binary numbers
• Addition / Subtraction of Binary Numbers
• Two’s Complement
Numbering System Shortcuts
It is very simple to convert binary numbers to octal or hexadecimal numbers since 8 is 2^3, and 16 is 2^4
In other words:
• 1 Octal digit = 3 binary digits
• 1 Hex digit - 4 binary digits
Binary to Octal
Notice the Pattern:• Largest 3 digit binary is 111
• 1 octal digit will represent a 3 digit binary number
• Highest Octal digit is 7
• Therefore: 1112 = 78
Binary to Octal
Relationship:Octal Binary
0 000
1 001
2 010
3 011
4 100
5 101
6 110
7 111
Does this table look familiar?
Practical Example
• applying octal values of rwx the chmod command (e.g., chmod 751).
• chmod 777
• chmod 755
• chmod 711
• chmod 644
Binary to Hexadecimal
Notice the Pattern:• Largest 4 digit binary is 1111
• 1 hex digit will represent a 4 digit binary number
• Highest hex digit is F
• Therefore: 11112 = F16
Binary to Hexadecimal
Relationship:Hexadecimal Binary Hexadecimal Binary
0 0000 8 1000
1 0001 9 1001
2 0010 A 1010
3 0011 B 1011
4 0100 C 1100
5 0101 D 1101
6 0110 E 1110
7 0111 F 1111
Convert Hex to Binary
Steps:• Convert Hex number to groups of
powers of 2.
• Convert to Binary number (Remember to drop leading zeros for first set of binary numbers - i.e. first left set)
Convert Hex to Binary
11F616
= 1 1 F 6
= 000(1) 000(1) (8)(4)(2)(1) 0(4)(2)0
= 1 0001 1111 0110= 10001111101102
000
Drop Leading zeros
Convert Binary to Hex
Steps:• Separate into 4 bit groups starting from
the right.
• Calculate decimal equivalent (in placeholders in powers of 2)
• Convert to Hexadecimal number
Convert Binary to Hex
10001111101102
=1 0001 1111 0110
=0001 0001 1111 0110= 1 1 (8)(4)(2)(1) 0(4)(2)0
= 1 1 15 6= 11F616
Converting Octal to Hexadecimal
• The easiest method to convert between Octal and Hexadecimal is to convert to binary as an intermediate step
• Regroup binary in groups of 4 for hexadecimal and 3 for octal
Storing Numbers
• Numeric information (stored as a non negative number) is often store in a computer in binary.
Eg.
• 1 byte (0 - 255 numbers)
• 2 bytes (0 - 65535)
• 4 bytes (0-4294967295)
Data Formats
Unsigned Binary• Data stored as a binary number, with
no way to express a negative quantity
Data Formats
Signed Binary• Data stored as a binary number, but
using a leading zero to represent a positive number, and the two’s complement of a binary number for a negative number
Adding / Subtracting Binary Numbers
• Addition:0 + 0 = 0
0 + 1 = 1, 1 + 0 = 1
1 + 1+ = 10
• Subtraction:0 - 0 = 0
1 - 1 = 0, 1 - 0 = 1
0 - 1 (Must borrow from next placeholder)
Therefore 10 - 1 = 1
Two’s Complement
• Simple method of subtracting two binary numbers by adding.
• Two Complement– Flip binary numbers (0 becomes 1, visa versa)– then add 1– Result becomes negative
• Therefore, short-hand method of representing negative integers