SME
Digital Logic Design · Problem type
Shift right
Use this for “Shift the 8-bit pattern 10110110₂ right by 2 places. What is the result, in binary and in decimal?”
Diagram
S
=
0xB6
>>
2
=
0x2D:
each
bit
moves
2
places
right,
2
zeros
come
in
at
the
left
and
the
last
2
drop
off,
⌊
182
2
2
⌋
=
45.
Bits are numbered from 0 at the right; a lit bit is one the operation changed.
This is an example. Type your own values to start a new problem.
S
=
⌊
N
÷
2
⌋
N₂
Number in binary
calculated
n
Width in bits
example
2ᵏ
Divisor
worked out (not typed)
S₂
Result in binary
calculated
Formulas
N₂
=
N
1,011 0,110₂ = 182
2ᵏ
=
2
k
4
=
2
2
S
=
⌊
N
2ᵏ
⌋
45
=
⌊
182
4
⌋
S₂
=
S
0,010 1,101₂ = 45
Assumptions
•
A logical right shift by k moves every bit k places right; k zeros fill in at the left.
•
Each place to the right halves a bit’s weight, so the shift divides by 2ᵏ and drops the bits shifted out.
•
The number is unsigned and n bits wide.
Step-by-step
WE KNOW
N = 182, n = 8, k = 2
FIND
number in binary (N₂), divisor (2ᵏ), result (S), result in binary (S₂)
Step 1 · Find number in binary (N₂)
Use N₂ = N
The binary digits are the remainders of repeated ÷ 2, read from the last.
N₂
=
182
182 ÷ 2 = 91 remainder 0
91 ÷ 2 = 45 remainder 1
45 ÷ 2 = 22 remainder 1
22 ÷ 2 = 11 remainder 0
11 ÷ 2 = 5 remainder 1
5 ÷ 2 = 2 remainder 1
2 ÷ 2 = 1 remainder 0
1 ÷ 2 = 0 remainder 1
182 = 10,110,110₂
N₂
=
1011
0110₂
Step 2 · Find divisor (2ᵏ)
Use 2ᵏ = 2ᵏ
Each
place
to
the
right
halves
the
weight,
so
k
places
divide
by
2ᵏ.
2ᵏ
=
2
2
2ᵏ = 4
Step 3 · Find result (S)
Use S = ⌊N ÷ (2ᵏ)⌋
Divide by 2ᵏ and drop the fraction: the fraction is the bits shifted out.
⌊
182
4
⌋
=
⌊45.5⌋
=
45
S
=
45
Step 4 · Find result in binary (S₂)
Use S₂ = S
Write
the
result
in
binary
at
the
same
width:
k
zeros
now
lead.
S₂
=
45
45 ÷ 2 = 22 remainder 1
22 ÷ 2 = 11 remainder 0
11 ÷ 2 = 5 remainder 1
5 ÷ 2 = 2 remainder 1
2 ÷ 2 = 1 remainder 0
1 ÷ 2 = 0 remainder 1
45 = 00,101,101₂
S₂
=
0010
1101₂
Check
Put the numbers back in. Both sides should match.
1,011 0,110₂ = 182 ✓
4
=
2
2
✓
45
=
⌊
182
4
⌋
✓
0,010 1,101₂ = 45 ✓
Topic check
See what you know: 5 questions on this topic
New questions each time. Pass to mark it complete.
Related lessons
Sequential logic and flip-flops
Main lesson
Counter modulus and output frequency
Use this for “A 4-bit counter (mod 16) runs on a 1 MHz clock: find its top bit’s frequency. How many flip-flops does a mod-10 counter need?”
JK flip-flop next state
Use this for “A JK flip-flop holds Q = 0 with J = K = 1. What is Q after the clock edge?”