levo

Data Types and Number Representation

Bitwise shifts

  • 3 things to know
  • Component 01
Start revising · £5/month

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.

Everything in your subscription

Runs, plus a mode for every other kind of session.

1Flash
2Imposter
3Fade
4Brain dump

Learn every subtopic in runs of four questions

Facts flash and fade, a wrong word hides in some of them, and a brain dump decides which questions are locked in.

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

Cram the night before, weakest topic first

A quick scan finds your weakest topics. Recall each fact you missed three times in a row.

If it matches, the search .
succeedsfailsrestarts

Blank Blitz consolidates the facts

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

✓What it iscovered
~Why it happenspartly there
How long it lastsnot there yet

Explain It tests your understanding

Explain a concept in your own words and see which of its points you covered.

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

Test It catches misconceptions

Spot the fault in a statement. The faults are the mistakes students make most often.

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.

Learn it in runs of four questions, each ending on a brain dump against the clock. Every question you lock in comes back the next day, then at longer gaps, each time just before you would forget it.

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