How to use the Left shift Calculator tool
- Enter the value to shift in the Binary digits field, for example 10110001.
- Enter how far to move it in the Number of positions field, from 0 to 4096.
- Select Left-shift. The Example button loads 10110001 with a shift of 2.
- Read the shifted binary number in the Result box.
- Select Copy to copy the result, or Clear to start over.
How a binary left shift works
A left shift by n moves each bit n places toward the high end and writes n zeros into the low end. Every single-place shift doubles the value, so shifting by n multiplies by 2^n. This is the operation behind the << operator in C, Java, JavaScript, Python and most other languages.
This calculator treats the input as an unsigned number of unlimited size. It does not model a fixed register, so bits never fall off the left end. The result is printed without leading zeros: 00010110 shifted by 3 comes back as 10110000.
Worked example: 10110001 shifted left by 2
10110001 is 177 in decimal. Shifting left by 2 appends two zeros and gives 1011000100, which is 708, or 177 times 4.
10110001 << 2 = 1011000100 (177 * 4 = 708)
00010110 << 3 = 10110000 (22 * 8 = 176)
1 << 7 = 10000000 (128)Fixed-width shifts and overflow
Hardware registers and typed integers have a fixed width, and a left shift there discards whatever moves past the top bit. An 8-bit register holding 10110001 becomes 11000100 after a shift of 2, because the leading 10 is lost. To reproduce that, keep only the rightmost 8 digits of this tool's result, or pass the result through the Binary Word size Converter with the target width.
Language rules differ once the shift count reaches the type width. In C and C++ that is undefined behavior. Java and JavaScript mask the count instead, so on a 32-bit int a shift by 32 leaves the value unchanged. Python integers grow without limit, which is the behavior you see here.
Accepted input and limits
Both fields are validated before the shift runs. An invalid value stops the calculation with an error message and no result.
- Binary digits: 1 to 65,536 characters of 0 and 1. A 0b prefix and spaces are removed first.
- Number of positions: a whole number from 0 to 4096. Fractions and blank values are rejected.
- A shift of 0 returns the number unchanged apart from dropped leading zeros.
- An input of all zeros always returns 0.
Frequently asked questions
Is a left shift the same as multiplying by 2?
Yes, for unsigned values with enough room. Each position doubles the number, so a shift by 3 multiplies by 8. In fixed-width types the equality breaks as soon as a 1 bit is pushed past the top of the word.
Why is the result longer than my input?
The calculator keeps every bit. Shifting an 8-digit number that starts with 1 by 2 positions needs 10 digits. Trim the result to your register width if you want the truncated value a CPU would hold.
What fills the empty positions after a left shift?
Zeros. A left shift always inserts 0 bits at the least significant end, for signed and unsigned values alike. There is no arithmetic variant of left shift that copies a sign bit.
What is the largest shift I can enter?
The Number of positions field accepts whole numbers from 0 to 4096. Shifting a single 1 by 4096 produces a 4,097-digit result, which the Result box shows in full.
How do I build a bit mask with a left shift?
Shift the single bit 1 by the index of the bit you want. Entering 1 with 7 positions returns 10000000, the mask for bit 7. In code this is the familiar 1 << n pattern used to set, clear or test one flag.
How is a left shift different from a rotate left?
A shift pushes new zeros in on the right and, in a fixed-width word, loses the bits that leave on the left. A rotation feeds those departing bits back in on the right, so no information is lost. Use the Rotate left Calculator for that.