levo

Data Types and Number Representation

Bitwise shifts

  • 3 things to know
  • Component 01

Overview

Recall questions on logical left and right shifts and their effect on value, bits lost off the end, arithmetic right shifts on two's complement numbers, rounding, compilers replacing multiplication with shifts, and extracting packed values.

What you need to know

Answer each one before you reveal it.

Your recallNot started
Key term

Shift 00010110 two places left. What is the result in binary and in denary?

Key term

Shift 01001100 two places right logically and check the result.

Key term

What is an arithmetic right shift, and how does it differ from a logical one?

Questions from this subtopic

Each one with the model answer underneath.

  1. 1

    What does a logical shift do to a binary pattern?

    Model answer

    It moves every bit a given number of places left or right. Bits pushed off the end are lost, and the positions vacated at the other end are filled with zeros. A logical shift makes no assumption about the pattern meaning a number, and in particular it treats the leftmost bit as an ordinary bit rather than a sign.

  2. 2

    What effect does a logical left shift of n places have on the value, and why?

    Model answer

    It multiplies the value by 2 to the power n. Every bit moves to a place worth twice as much, and doing that n times multiplies by 2 n times. It is the binary equivalent of adding zeros on the right of a denary number to multiply by ten — but the word is a fixed width, so once a significant bit falls off the left-hand end the result has overflowed and is no longer the value multiplied.

  3. 3

    Shift 00010110 two places left. What is the result in binary and in denary?

    Model answer

    01011000, which is 88. The original is 22, and shifting two places left multiplies by 4, giving 88. Note the two zeros shifted in at the right-hand end.

  4. 4

    Shift the unsigned byte 10110000 one place left. What goes wrong?

    Model answer

    The result is 01100000, which is 96. The original value was 176, and doubling it should give 352, but 352 will not fit in eight bits. The leading 1 was pushed off the left-hand end and lost, taking 256 with it, and 352 minus 256 is indeed 96. This is where the shift-as-multiplication shortcut stops working: it is only valid while no significant bit falls off the top.

  5. 5

    What effect does a logical right shift have, and what is lost?

    Model answer

    It divides an unsigned value by 2 to the power n, and what is lost is the remainder. The bits pushed off the right-hand end are the fractional part of the answer and they are simply discarded, so a right shift performs integer division that always rounds down. Shifting 00001011, which is 11, two places right gives 00000010, which is 2, not 2.75.

  6. 6

    Shift 01001100 two places right logically and check the result.

    Model answer

    00010011, which is 19. The original is 76, and 76 divided by 4 is exactly 19, so nothing was lost this time because the two bits shifted off the end were both zero.

Other ways to work this

The same content, four other ways.

What is inside Levo

Six ways to work the same material.

1Closed book
2Open book
3Closed book

The 3-step method, run for you

Answer cold, learn it, then prove it stuck. Levo tracks the jump between your first attempt and your last.

Processors: Structure, Performance and Types
Input, Output and Storage
Systems Software
Applications Generation

Cram a whole paper in one sitting

Sort every topic into what you know and what you do not, then drill only the weak ones.

If it matches, the search .
succeedsfailsrestarts

Blank Blitz makes facts automatic

Rapid timed gap-fills on the terms and numbers you need to recall without thinking.

A0 + 0 gives 0.
B0 + 1 gives 1.
C1 + 1 gives 0 carry 1.

Build It gets the exam shape right

Assemble a full-mark answer from its marking points, in the order an examiner wants them.

A global variable means a variable reachable from anywhere in the program.
TrueFalse

Test It catches misconceptions

Spot the fault in a statement. The traps are the mistakes students actually make.

721941163128510

Brain Breaks between sessions

Short focus games to reset attention, so the next set lands better than the last.

Every question in Data Types and Number Representation, on a schedule.

Attempt a question from memory, write the correct version, then attempt it again. Levo records the jump between your first attempt and your last, and brings each question back on the day you are due to forget it.

Or £46 a year, about £3.83 a month. Cancel anytime.