Decimal, Hexadecimal and Binary Numbers, Study notes of Mechanics

o Binary numbers are a code, and represent what the programmer intends for the code o Convert binary and hex numbers to unsigned decimal.

Typology: Study notes

2021/2022

Uploaded on 08/05/2022

nguyen_99
nguyen_99 🇻🇳

4.2

(80)

1K documents

1 / 7

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
Decimal, Hexadecimal and Binary Numbers
oBinary numbers are a code, and represent what the programmer
intends for the code
oConvert binary and hex numbers to unsigned decimal
oConvert unsigned decimal to hex
oUnsigned number line and wheel
oSigned number line and wheel
oBinary, Hex, Signed and Unsigned Decimal
oSigned number representation --- 2's Complement form
oUsing the 1's complement table to find 2's complements of hex
numbers
oOverflow and Carry
oAddition and subtraction of binary and hexadecimal numbers
oThe Condition Code Register (CCR): N, Z, V and C bits
Binary Hex Decimal
0000
0001
0010
0011
0100
0101
0110
0111
1000
1001
1010
1011
1100
1101
1110
1111
0
1
2
3
4
5
6
7
8
9
A
B
C
D
E
F
0
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
What does a number represent?
Binary numbers are a code, and represent what the programmer intends for the code.
0x72 Some possible meanings:
’r’ (ASCII)
INC MEM (hh ll) (HC12 instruction)
2.26V (Input from A/D converter)
11410 (Unsigned number)
11410 (Signed number)
Set temperature in room to 69 °F
pf3
pf4
pf5

Partial preview of the text

Download Decimal, Hexadecimal and Binary Numbers and more Study notes Mechanics in PDF only on Docsity!

• Decimal, Hexadecimal and Binary Numbers

o Binary numbers are a code, and represent what the programmer

intends for the code

o Convert binary and hex numbers to unsigned decimal

o Convert unsigned decimal to hex

o Unsigned number line and wheel

o Signed number line and wheel

o Binary, Hex, Signed and Unsigned Decimal

o Signed number representation --- 2's Complement form

o Using the 1's complement table to find 2's complements of hex

numbers

o Overflow and Carry

o Addition and subtraction of binary and hexadecimal numbers

o The Condition Code Register (CCR): N, Z, V and C bits

Binary Hex Decimal 0000 0001 0010 0011 0100 0101 0110 0111 1000 1001 1010 1011 1100 1101 1110 1111

0 1 2 3 4 5 6 7 8 9 A B C D E F

What does a number represent? Binary numbers are a code, and represent what the programmer intends for the code. 0x72 Some possible meanings: ’r’ (ASCII) INC MEM (hh ll) (HC12 instruction) 2.26V (Input from A/D converter) 11410 (Unsigned number) 11410 (Signed number) Set temperature in room to 69 °F

Set cruise control speed to 120 mph Binary to Unsigned Decimal: Convert Binary to Unsigned Decimal (^1111011 ) 1 x 2^6 + 1 x 2 5 + 1 x 2 4 + 1 x 2 3 + 0 x 2 2 + 1 x 2 1 + 1 x 2 0 1 x 64 + 1 x 32 + 1 x 16 + 1 x 8 + 0 x 4 + 1 x 2 + 1 x 1 (^123 ) Hex to Unsigned Decimal Convert Hex to Unsigned Decimal 82D6 (^16) 8 x 16^3 + 2 x 16^2 + 13 x 16^1 + 6 x 16^0 8 x 4096 + 2 x 256 + 13 x 16 + 6 x 1 (^33494 ) Unsigned Decimal to Hex Convert Unsigned Decimal to Hex Division Q R Decimal Hex 721/ 45/ 2/

D

721 10 = 2D1 16

Unsigned Number Line: Numbers go from 0 to ∞ Unsigned Number Wheel: Numbers go from 0 to 2N − 1

Binary, Hex and Decimal (Signed & Unsigned) Numbers (4-bit representation) Binary Hex Decimal Unsigned Signed 0000 0 0 0 0001 1 1 1 0010 2 2 2 0011 3 3 3 0100 4 4 4 0101 5 5 5 0110 6 6 6 0111 7 7 7 1000 8 8 - 1001 9 9 - 1010 A 10 - 1011 B 11 - 1100 C 12 - 1101 D 13 - 1110 E 14 - 1111 F 15 -

Signed Number Representation in 2’s Complement Form: If the most significant bit (MSB) is 0 (most significant hex digit 0−7), then the number is positive. Get decimal equivalent by converting number to decimal, and use the + sign. Example for 8−bit number: 3A 16 −> + ( 3 x 16^1 + 10 x 16^0 ) (^10)

  • ( 3 x 16 + 10 x 1 ) (^10) + 58 (^10) If the most significant bit is 1 (most significant hex digit 8−F), then the number is negative. Get decimal equivalent by taking 2’s complement of number, converting to decimal, and using − sign. Example for 8−bit number: A3 16 −> - (5D) (^16)
  • ( 5 x 16^1 + 13 x 16^0 ) (^10)
  • ( 5 x 16 + 13 x 1 ) (^10) - (^93 ) One’s complement table makes it simple to finding 2’s complements To take two’s complement, add one to one’s complement. Take two’s complement of D0C3 : 2F3C + 1 = 2F3D

Note: Not all HC12 instructions change CCR bits. A bit in the CCR is the result of the last executed instruction which affects that bit. For example, consider the following instruction sequence: aba ; Add B to A staa $0900 ; Store A in address $ The ABA instruction will change the H, N, Z, V and C bits of the CCR. The STAA instruction will change the N and Z bit, and clear the V bit. After the two instructions, the H and C bits will reflect the result of the ABA instruction; the N and Z bits will reflect the result of the STAA instruction (was the number stored negative or zero?), and the V bit will be 0. Overflow occurs only under certain addition and subtraction operations

  • If you add a positive and a negative number, on overflow never occurs.
  • If you subtract two positive numbers, an overflow never occurs.
  • If you subtract two negative numbers, and overflow never occurs.