1’s and 2’s complement

14
1’s and 2’s complement

description

1’s and 2’s complement. One’s Complement (4-bit binary). ( + )  ditulis seperti biasa ( - )  “1” diubah menjadi “0” dan “0” diubah menjadi “1”. Two’s Complement (4-bit binary). ( + )  ditulis seperti biasa ( - )  “1” diubah menjadi “0” dan “0” diubah menjadi “1” - PowerPoint PPT Presentation

Transcript of 1’s and 2’s complement

Page 1: 1’s and 2’s complement

1’s and 2’s complement

Page 2: 1’s and 2’s complement

One’s Complement (4-bit binary)Decimal Binary

( + ) ( - )7 0111 10006 0110 10015 0101 10104 0100 10113 0011 11002 0010 11011 0001 11100 0000 1111

( + ) ditulis seperti biasa

( - ) “1” diubah menjadi “0” dan “0” diubah menjadi “1”

Page 3: 1’s and 2’s complement

Two’s Complement (4-bit binary)Decimal Binary

( + ) ( - )8 - 10007 0111 10016 0110 10105 0101 10114 0100 11003 0011 11012 0010 11101 0001 11110 0000 -

( + ) ditulis seperti biasa

( - ) “1” diubah menjadi “0” dan “0” diubah menjadi “1”Tambahkan “1”

Page 4: 1’s and 2’s complement

Contoh 2’s ComplementDesimal = (+5)Binary = 0101

Desimal = (-5)Binary :1. Ubah ke binary biasa = 01012. Ganti “0” menjadi “1” dan “1” menjadi “0”

= 10103. Tambahkan dengan “1” = 1011

Page 5: 1’s and 2’s complement

Penjumlahan pada binary• 0 + 0 = 0• 0 + 1 = 1• 1 + 0 = 1• 1 + 1 = 0, and carry 1 to the next more

significant bit

Page 6: 1’s and 2’s complement

Contoh penjumlahan binary

1 10 0 0 1 1 0 1 0 = 26

+ 0 0 0 0 1 1 0 0 = 120 0 1 0 0 1 1 0 = 38

Page 7: 1’s and 2’s complement

Pengurangan pada binary• 0 - 0 = 0• 0 - 1 = 1, and borrow 1 from the next

more significant bit• 1 - 0 = 1• 1 - 1 = 0

Page 8: 1’s and 2’s complement

Contoh pengurangan binary

Page 9: 1’s and 2’s complement

Penjumlahan pada 1’s complement

6 + 3 = ….63==9

6 - 3 = …. 6- 3---- 3

0110- 0011 0011

Page 10: 1’s and 2’s complement

Pengurangan pada 1’s complement1 2

3

4 5

overflow

Page 11: 1’s and 2’s complement

Pengurangan pada 1’s complement

Page 12: 1’s and 2’s complement

5 +2 = …0101 5

+ 0010 20111 7

Penjumlahan pada 2’s complement

5 + (-2) = …0101 5

+ 1110 -2 10011 3

Page 13: 1’s and 2’s complement

Pengurangan pada 2’s complement

Page 14: 1’s and 2’s complement

Pengurangan pada 2’s complement

Overflow : Discard!!!