Data Structure Lect11
Data Structure Lect11
Lecture 11
Topics
Conversion between Binary Octal and Hexadecimal
What is the decimal expansion of the number with octal expansion (7016)8?
Solution:
Using the definition of a base b expansion with b = 8 tells us that
(7016)8 = 7 · 83 + 0 · 82 + 1 · 81 + 6 .80
= 3598.
Decimal Expansion of Binary Number
What is the decimal expansion of the integer that has (1 0101 1111) 2 as its binary
expansion?
Solution:
(10101 1111)2= 1 · 28 + 0 · 27 + 1 · 26 + 0 · 25 + 1 · 24 + 1 · 23 + 1 · 22 + 1 · 21 + 1 · 20
= 351.
Octal and Hexadecimal Expansion to Binary
OCTAL to Binary
To convert (765)8 into binary notation, we replace each octal digit by a block of three
binary digits.
7 = 111, 6 = 110, 5 = 101
These blocks are 111, 110, and 101.
Hence, (765) 8 = (1 1111 0101) 2.
Hexadecimal to Binary
To convert (A8D) 16 into binary notation, we replace each hexadecimal digit by a block
of four binary digits.
A = 10 =1010, 8 = 1000, D = 13 = 1101
These blocks are 1010, 1000, and 1101.
Hence, (A8D) 16 = (1010 1000 1101) 2
ALGORITHM 1 Constructing Base b Expansions
Every integer greater than 1 can be written uniquely as a prime or as the product
of two or more primes where the prime factors are written in order of
nondecreasing size.
Example:
The prime factorizations of 100, 641, 999, and 1024 are given by
100 = 2 · 2 · 5 · 5 = 22 52,
641 = 641,
999 = 3 · 3 · 3 · 37 = 33 · 37,
1024 = 2 · 2 · 2 · 2 · 2 · 2 · 2 · 2 · 2 · 2 = 210.
Fermat’s Little Theorem
If p is prime and a is an integer not divisible by p,
then ap-1 ≡ 1 (mod p).
Furthermore, for every integer a we have
ap ≡ a (mod p)
Use Fermat’s little theorem to compute 3302 mod 5, 3302 mod 7, and 3302 mod 11.