In digital electronics, to shift is to move all the bits of a register to the left (left shift) or right (right shift). The last bit in the shift direction is "shifted out", while a new bit is supplied for the first.
1 -> |01100110| ->

  -> |10110011| -> 0
See also shift register.
Perl function:
shift @array

Removes and returns the first value of @array, moving the other elements down and reducing the length of @array by 1. If @array contains no elements, the undefined value is returned.

If no argument is given, shift affects @ARGV (in main program) or @_ (in a subroutine).

See also push, pop and unshift.

Back to Perl

The shift operation of a microprocessor is an amazingly useful function which generally takes very few cycles to complete, often as few as one. It can be used for (among many other things) multiplication and division by two (to a point.) Using this feature repeatedly can also multiply and divide by powers of two through repetition.

Let us look at the base 10 number "1" as represented in one byte of binary:

00000001 == 110

If we shift it left (towards the MSB or most significant bit) once, its value doubles.

00000010 == 210

Shifting it left again will double it again:

00000100 == 410

Now let's try this with a larger number, like for example 42.

00101010 == 4210
01010100 == 8410

Shifting right (towards the LSB or least significant bit) will of course divide by two. The only problem becomes when you shift a bit into the bit bucket. You can solve this problem by shifting with carry on some architectures, and then look at the carry bit to determine if you have overflowed the register. If you have done so on a shift right, then your result is the result plus 0.5. If you have done so on a shift left, then the result is the result plus 256 in the case of eight bits, or 2 raised to the number of bits in the register in all cases.

There are other forms of the shift instructions present on some architectures. I will use the x86 instruction set by way of example. x86 includes SAL (shift arithmetic left) and SAR (shift arithmetic right) instructions. SHL (shift left) and SAL do the same thing; for each step, each bit is shifted left one place (from LSB towards MSB) and a 0 is brought into the LSB. However, SAR does something differently; The value of the MSB is preserved, thus preserving the sign of signed integers.

The shift function is related to the rotate operations, which instead of losing the MSB or LSB, move the ordinarily lost bit into its antithesis. Hence a rotate right (ROR) will shift all bits toward the LSB, and move the LSB into the MSB.

The shift key on keyboards got its name after the Remington #2 typewriter.

The first typewriter, built in 1868, only typed in capital letters. The second-generation model, in 1878, allowed UPPERCASE and lowercase letters. The trick was that each typebar (the piece that would swing up and hit the page with the letter) now had an Uppercase and lowercase letter on it. Pressing the "Shift" key would actually shift the typebars in order to shift the Uppercase keys into position.

Of course, the modern typewriters and word processors and electronic devices no longer need to shift mechanically, but the name stuck, and carried over to computer use, as the QWERTY keyboard layout was used to mimic a conventional typewriter.

I still feel you next to me
Your hands on me
My hands on you

A moment of intimacy
A moment of intensity...

Something shifted

A new connection
A shift to closer
In this beautiful moment

more of that please

There is something different
Your eyes look at me
I feel you looking AT me
Possibly looking into me

I like this shift

Shift (?), v. t. [imp. & p. p. Shifted; p. pr. & vb. n. Shifting.] [OE. shiften, schiften, to divide, change, remove. AS. sciftan to divide; akin to LG. & D. schiften to divide, distinguish, part Icel. skipta to divide, to part, to shift, to change, Dan skifte, Sw. skifta, and probably to Icel. skifa to cut into slices, as n., a slice, and to E. shive, sheave, n., shiver, n.]


To divide; to distribute; to apportion.


To which God of his bounty would shift Crowns two of flowers well smelling.


To change the place of; to move or remove from one place to another; as, to shift a burden from one shoulder to another; to shift the blame.

Hastily he schifte him[self].
Piers Plowman.

Pare saffron between the two St. Mary's days, Or set or go shift it that knowest the ways.


To change the position of; to alter the bearings of; to turn; as, to shift the helm or sails.

Carrying the oar loose, [they] shift it hither and thither at pleasure.
Sir W. Raleigh.


To exchange for another of the same class; to remove and to put some similar thing in its place; to change; as, to shift the clothes; to shift the scenes.

I would advise you to shift a shirt.


To change the clothing of; -- used reflexively.


As it were to ride day and night; and . . . not to have patience to shift me.


To put off or out of the way by some expedient.

"I shifted him away."


To shift off, to delay; to defer; to put off; to lay aside. -- To shift the scene, to change the locality or the surroundings, as in a play or a story.

Shift the scene for half an hour;
Time and place are in thy power.


© Webster 1913.

Shift, v. i.


To divide; to distribute.


Some this, some that, as that him liketh shift. Chaucer.


To make a change or changes; to change position; to move; to veer; to substitute one thing for another; -- used in the various senses of the transitive verb.

The sixth age shifts Into the lean and slippered pantaloon. Shak.

Here the Baillie shifted and fidgeted about in his seat. Sir W. Scott.


To resort to expedients for accomplishing a purpose; to contrive; to manage.

Men in distress will look to themselves, and leave their companions to schift as well as they can. L'Estrange.


To practice indirect or evasive methods.

All those schoolmen, though they were exceeding witty, yet better teach all their followers to shift, than to resolve by their distinctions. Sir W. Raleigh.

5. Naut.

To slip to one side of a ship, so as to destroy the equilibrum; -- said of ballast or cargo; as, the cargo shifted.


© Webster 1913.

Shift (?), n. [Cf. Icel skipti. See Shift, v. t.]


The act of shifting.

Specifically: (a)

The act of putting one thing in the place of another, or of changing the place of a thing; change; substitution


My going to Oxford was not merely for shift of air. Sir H. Wotton.

(b) A turning from one thing to another; hence, an expedient tried in difficalty; often, an evasion; a trick; a fraud. "Reduced to pitiable shifts."


I 'll find a thousand shifts to get away.

Little souls on little shifts rely.


Something frequently shifted; especially, a woman's under-garment; a chemise.


The change of one set of workmen for another; hence, a spell, or turn, of work; also, a set of workmen who work in turn with other sets; as, a night shift.


In building, the extent, or arrangement, of the overlapping of plank, brick, stones, etc., that are placed in courses so as to break joints.

5. Mining

A breaking off and dislocation of a seam; a fault.

6. Mus.

A change of the position of the hand on the finger board, in playing the violin.

To make shift, to contrive or manage in an exigency. "I shall make shift to go without him."


[They] made a shift to keep their own in Ireland.


© Webster 1913.

Log in or register to write something here or to contact authors.