Docsity

DECIMAL, BINARY, AND HEXADECIMAL, Study notes of English

Partial preview of the text

Download DECIMAL, BINARY, AND HEXADECIMAL and more Study notes English in PDF only on Docsity!

DECIMAL, BINARY, ANDHEXADECIMAL

Decimal Numbering System Ten symbols: 0, 1, 2, 3, 4, 5, 6, 7, 8, 9Represent larger numbers as a sequence of digits^ •^ Each digit is one of the available symbolsExample: 7061 in decimal (base 10)^ •^7061 = (7 x 10^10

32 ) + (0 x 10) + (6 x 10

10 ) + (1 x 10)

BASE CONVERSION

  • Question What is
    • in base 10?
      • (A) 32^10 (B) 34^10 (C) 7^10 (D) 28^10 (E)^35
  • Binary Numbering System Binary is base 2 • Symbols: 0, 1Convention: - = 10 = 0b10 - Example: What is 0b110 in base 10? • 0b110 = - 2 = (1 x - 1 ) + (1 x 2) + (0 x
    • Base 10 Base 8 Base 2^0 0 01 1 12 2 103 3 114 4 1005 5 1016 6 1107 7 1118 10 10009 11 1001^0 ) =
  • Hexadecimal Number System Hexadecimal is base 16 (>10) • Symbols? 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, …?Convention: - = 10 = 0x10 - Example: What is 0xA5 in base 10? • 0xA5 = A - = (10 x - 10 ) + (5 x 16) =
    • 8, 9, A, B, C, D, E, F
  • Question Which of the following orderings is correct?(A) 0xC < 0b1010 < 11(B) 0xC < 11 < 0b1010(C) 11 < 0b1010 < 0xC(D) 0b1010 < 11 < 0xC(E) 0b1010 < 0xC <
  • Challenge Question Convert
    • to binary
      • Hints:^3 •^2 = 8^2 •^2 = 4^1 •^2 = 2^0 •^2 =

Converting from Decimal to Binary Given a decimal number N:^ •^ List increasing powers of 2 from right to left until ≥ N^ •^ From left to right, ask is that (power of 2) ≤ N?^ –^ If^ YES , put a 1 below and subtract that power from N^ –^ If^ NO , put a 0 below and keep goingExample for 13:

4 2 =^

3 2 2 =8^2 =^

1 0 2 =2^2 =

5 1 0

Converting Binary

Hexadecimal

Hex^ Binary^ •^ Substitute hex digits, then dropleading zeros^ •^ Example: 0x2D in binary^ –^ 0x2 is 0b0010, 0xD is 0b1101^ –^ Drop two leading zeros, answer is 0b101101Binary^ Hex^ •^ Pad with leading zeros until multipleof 4, then substitute groups of 4^ •^ Example: 0b101101^ –^ Pad to 0b 0010 1101^ –^ Substitute to get 0x2D

Base 10 Base 16 Base 2^0

(^00001 1 00012 2 00103 3 00114 4 01005 5 01016 6 01107 7 01118 8 10009 9 100110) A (^101011) B (^101112) C (^110013) D (^110114) E (^111015) F 1111

Binary^

Hex Practice

Convert 0b100110110101101^ •^ How many digits?^ •^ Pad: 0b 0100 1101 1010 1101^ •^ Substitute: 0x4DAD

Base 10 Base 16 Base 2^0

(^00001 1 00012 2 00103 3 00114 4 01005 5 01016 6 01107 7 01118 8 10009 9 100110) A (^101011) B (^101112) C (^110013) D (^110114) E (^111015) F 1111 ? 15

BINARY ENCODING

Numerical Encoding AMAZING FACT: You can represent

anything

countable using numbers!^ •^ Need to agree on an encoding^ •^ Kind of like learning a new languageExamples:^ •^ Decimal Numbers: 0

0b0, 1^ 0b1, 2

0b10, etc.

-^ English Letters: BJC

0x424A43, yay

0x

-^ Emoticons:

😃^ 0x0,^ 😞^ 0x1,

😎^ 0x2,^ 😇^ 0x3,

😈^ 0x4,^ 🙋^ 0x

So What’s It Mean? A sequence of bits can have many meanings!Consider the hex sequence 0x4E6F21Common interpretations include:^ •^ The decimal number 5140257^ •^ The characters “No!”^ •^ The background color of this slide^ •^ The real number 7.203034 x 10

-39^ [floating point]

It is up to the program/programmer to decide howto interpret the sequence of bits

Summary Humans think about numbers in decimal;computers think about numbers in binary^ •^ Base conversion to go between^ •^ Hex is more human-readable than binaryAll information on a computer is in binary^ •^ Nice because big difference between “high” and “low”Binary encoding can represent

anything!

-^ Program needs to know how to interpret bits