Lecture 2: Decimal, Binary, Octal and Hexadecimal Numbers Aneel Ahmed
Convert from Decimal to Binary <ul><li>(26) 10  = 16 + 8 + 2 = (11010) 2 </li></ul><ul><li>(100) 10  = 64 + 32 + 4 = (1100...
Convert from Binary to Octal <ul><li>(1000) 2  = (10) 8 </li></ul><ul><li>(1001010111) 2  = (1127) 8 </li></ul><ul><li>(11...
Convert from Octal to Binary <ul><li>(777) 8 =  (111 111 111) 2 </li></ul><ul><li>(123) 8 =  (001 010 011) 2 </li></ul><ul...
Convert from Binary to Hex <ul><li>(1000) 2  = (8) 16 </li></ul><ul><li>(1010) 2  = (A) 16 </li></ul><ul><li>(1011) 2  = (...
Convert from Hex to Binary <ul><li>(ABCDEF) 16  = (101010111100110111101111) 2 </li></ul><ul><li>(9A) 16  = (10011010) 2 <...
Handling Negatives <ul><li>These methods work as long as your values are zero or positive. What about if your values can b...
Negative Binary Numbers <ul><li>(-12) 10  = (1 1100) 2   where 1100 is the value of twelve in binary  and 1 represents whe...
Binary Addition <ul><li>23 + 48 = 71 </li></ul><ul><li>0 + 0 = 0 </li></ul><ul><li>0 + 1 = 1 </li></ul><ul><li>1 + 1 = 10 ...
Binary Subtraction <ul><li>0 – 0 = 0 </li></ul><ul><li>1 – 0 = 1 </li></ul><ul><li>1 – 1 = 0 </li></ul><ul><li>0 – 1 = 1 <...
One’s Complement <ul><li>In one's complement, positive numbers are represented as usual in regular binary.  </li></ul><ul>...
Upcoming SlideShare
Loading in …5
×

Lecture 2 itc

511 views
433 views

Published on

Published in: Education, Technology
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total views
511
On SlideShare
0
From Embeds
0
Number of Embeds
2
Actions
Shares
0
Downloads
0
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

Lecture 2 itc

  1. 1. Lecture 2: Decimal, Binary, Octal and Hexadecimal Numbers Aneel Ahmed
  2. 2.
  3. 3.
  4. 4.
  5. 5.
  6. 6.
  7. 7. Convert from Decimal to Binary <ul><li>(26) 10 = 16 + 8 + 2 = (11010) 2 </li></ul><ul><li>(100) 10 = 64 + 32 + 4 = (1100100) 2 </li></ul><ul><li>(15) 10 = 8 + 4 + 2 + 1 = (1111) 2 </li></ul><ul><li>(79) 10 = 64 + 8 + 4 + 2 + 1 = (1001111) 2 </li></ul>
  8. 8.
  9. 9.
  10. 10.
  11. 11. Convert from Binary to Octal <ul><li>(1000) 2 = (10) 8 </li></ul><ul><li>(1001010111) 2 = (1127) 8 </li></ul><ul><li>(111111) 2 = (77) 8 = (63) 10 </li></ul><ul><li>(100111011101010110) 2 = (473526) 8 </li></ul>
  12. 12.
  13. 13. Convert from Octal to Binary <ul><li>(777) 8 = (111 111 111) 2 </li></ul><ul><li>(123) 8 = (001 010 011) 2 </li></ul><ul><li>(123) 8 = (001 010 011) 2 </li></ul><ul><li>(20) 8 = (010 000) 2 = (16) 10 </li></ul><ul><li>(100) 8 = (001 000 000) 2 = (64) 10 </li></ul>
  14. 14. Convert from Binary to Hex <ul><li>(1000) 2 = (8) 16 </li></ul><ul><li>(1010) 2 = (A) 16 </li></ul><ul><li>(1011) 2 = (B) 16 </li></ul><ul><li>(1100) 2 = (C) 16 </li></ul><ul><li>(1101) 2 = (D) 16 </li></ul><ul><li>(1110) 2 = (E) 16 </li></ul><ul><li>(1111) 2 = (F) 16 </li></ul><ul><li>(100010110) 2 = (116) 16 </li></ul><ul><li>(1001 0100 1111 1011 1101) 2 = (94FBD) 16 </li></ul>
  15. 15. Convert from Hex to Binary <ul><li>(ABCDEF) 16 = (101010111100110111101111) 2 </li></ul><ul><li>(9A) 16 = (10011010) 2 </li></ul><ul><li>(7F) 16 = (01111111) 2 </li></ul><ul><li>(10) 16 = (00010000) 2 = (16) 10 </li></ul>
  16. 16.
  17. 17. Handling Negatives <ul><li>These methods work as long as your values are zero or positive. What about if your values can be negative? In human notation, we just write a &quot;-&quot; in front, to indicate the sign of the number. (We do sometimes also write a &quot;+&quot; for positives, although usually we just assume it). </li></ul><ul><li>The same trick can be used to write negatives in binary, except now instead of writing &quot;+&quot; or &quot;-&quot; for the sign, we can write &quot;0&quot; to mean &quot;positive&quot; and &quot;1&quot; to mean &quot;negative&quot;. You can then write the rest of the value as the absolute value of your number. </li></ul><ul><li>This is called signed magnitude representation </li></ul>
  18. 18. Negative Binary Numbers <ul><li>(-12) 10 = (1 1100) 2 where 1100 is the value of twelve in binary and 1 represents whether it is negative or positive (0 = zero/positive, 1 = negative). </li></ul><ul><li>By contrast, positive 12 would be written 01100. This basically just mirrors how we write numbers on paper. </li></ul><ul><li>Question: What does #b(110011) represent? </li></ul><ul><li>Answer: It depends: Is this a regular unsigned binary value? Or is it signed magnitude? Unsigned: 32 + 16 + 2 + 1 = 51 Signed Mag: (negative) 16 + 2 + 1 = -19 </li></ul><ul><li>Key idea: when interpreting a binary number, in addition to knowing the bits, you also have to know what representation to interpret it against. </li></ul>
  19. 19. Binary Addition <ul><li>23 + 48 = 71 </li></ul><ul><li>0 + 0 = 0 </li></ul><ul><li>0 + 1 = 1 </li></ul><ul><li>1 + 1 = 10 </li></ul><ul><li>Try a few examples of binary addition: </li></ul><ul><ul><li>111 + 110 </li></ul></ul><ul><ul><li>101 + 111 </li></ul></ul><ul><ul><li>111 + 111 </li></ul></ul>
  20. 20. Binary Subtraction <ul><li>0 – 0 = 0 </li></ul><ul><li>1 – 0 = 1 </li></ul><ul><li>1 – 1 = 0 </li></ul><ul><li>0 – 1 = 1 </li></ul><ul><li>Try: 10000 - 10 </li></ul>
  21. 21. One’s Complement <ul><li>In one's complement, positive numbers are represented as usual in regular binary. </li></ul><ul><li>However, negative numbers are represented differently. To negate a number, replace all zeros with ones, and ones with zeros - flip the bits. </li></ul>

×