Vous êtes sur la page 1sur 14

# Binary Number Systems and Codes

## Sistem Komputer NAROTAMA

02 NUMBERS Page 1

Positional Numbers
528.4610 = (5 x 102) + (2 x 101) + (8 x 100) + (4 x 10-1) + (6 x 10-2)
527.468 = (5 x 82) + (2 x 81) + (7 x 80) + (4 x 8-1) + (6 x 8-2) 528.465 = illegal why? 101011.112 = (1 x 25) + (0 x 24) + (1 x 23) + (0 x 22) + (1 x 21) + (1 x 20) + (1 x 2-1) + (1 x 2-2)

## Sistem Komputer NAROTAMA

02 NUMBERS Page 2

Binary Numbers
101011.112 = (1 x 25 ) + (0 x 24 ) + (1 x 23 ) + (0 x 22 ) + (1 x 21 ) + (1 x 20 ) + (1 x 2-1 ) + (1 x 2-2 ) Convert to Base 10: = 32 + 0 + 8 + 0 + 2 + 1 + + = 43.7510

## Sistem Komputer NAROTAMA

02 NUMBERS Page 3

Commonly used for binary data
1 hex digit == 4 binary digits (bits)

## Need more digits

Use 0-9, A-F
A-F are for 10-15
FA216 = 15 x 162 + 10 x 161 + 2 x 160 FA216 = 1111 1010 0010 0001
Each group of 4 bits 1 hex digit
Sistem Komputer NAROTAMA
02 NUMBERS Page 4

Other Codes
BCD ASCII Gray

## Sistem Komputer NAROTAMA

02 NUMBERS Page 5

## Binary Coded Decimal (BCD)

Decimal Digit 0 1 2 3 4 5 6 7 8 9

## Convert 249610 to BCD Code

BCD 0000 0001 0010 0011 0100 0101 0110 0111 1000 1001

2
0 0 1 0

4
0 1 0 0

9
1 0 0 1

6
0 1 1 0

## Note this is very different from converting to binary which yields:

1 0 0 1 1 1 0 0 0 0 0 02

## Sistem Komputer NAROTAMA

02 NUMBERS Page 6

## ACSII Code (partial)

Character c d e f g h I j k l m n o p q 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 ASCII Code 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 0 0 0 0 0 1 1 1 1 1 1 1 1 1 0 0 1 1 1 1 0 0 0 0 1 1 1 1 0 0 1 0 0 1 1 0 0 1 1 0 0 1 1 0 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1

Binary Codes

## Sistem Komputer NAROTAMA

02 NUMBERS Page 7

Binary Codes
Number 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 Gray Code 0000 0001 0011 0010 0110 0111 0101 0100 1100 1101 1111 1110 1010 1011 1001 1000

Gray Code

## Only one bit changes with each number increment

Not a weighted code Useful for interfacing to some physical systems

## Sistem Komputer NAROTAMA

02 NUMBERS Page 8

## Gray Codes are Not Unique

Number 0 1 2 3 4 5 6 7 Gray Code 000 001 011 010 110 111 101 100

## Sistem Komputer NAROTAMA

02 NUMBERS Page 9

0+0=0 0+1=1 1+0=1 1 + 1 = 0 and carry 1 to the next column
Examples:
Carries

1 1 1

## Sistem Komputer NAROTAMA

02 NUMBERS Page 10

## Binary Addition w/Overflow

Add 4510 and 4410 in binary

1 1

## (4510) (4410) (8910)

Carries

If the operands are unsigned, you can use the final carry-out as the MSB of the result. Adding 2 k bit numbers k+1 bit result

## Sistem Komputer NAROTAMA

02 NUMBERS Page 11

1 1 1

## (1510) (110) (010)

If you dont want a 5-bit result, just keep the lower 4 bits. This is insufficient to hold the result (16). It rolls over back to 0.

## Sistem Komputer NAROTAMA

02 NUMBERS Page 12

Codes - Summary
Bits are bits
Modern digital devices represent everything as collections of bits A computer is one such digital device

## You can encode anything with sufficient 1s and 0s

Text (ASCII) Computer programs (C code, assembly code, machine code) Sound (.wav, .mp3, ) Pictures (.jpg, .gif, .tiff)

## Sistem Komputer NAROTAMA

02 NUMBERS Page 13