How to Use the Left Shift Calculator
Enter one integer, choose its base and width, then set a nonnegative shift count. The result and binary visualization update immediately.
A left shift calculator moves an integer’s bits left, inserts zeros on the right, and displays the result in binary, decimal, and hexadecimal. Choose Auto, 8-bit, 16-bit, 32-bit, or 64-bit width to see moved, filled, and discarded bits before using the value in code, a register, or a packed data field.
46 Hex0x2E Enter one integer, choose its base and width, then set a nonnegative shift count. The result and binary visualization update immediately.
Calculator Setup Walkthrough
23 decimal00010111 << 146 decimal / 0x2ESelect the format that matches the input:
23, 64, or 25500010111 or 1111000017, 2D, or FFThe same text can mean different values in different bases. For example, 17 is decimal seventeen in Decimal mode but decimal twenty-three in Hex mode.
The shift count is the number of positions to move. Use Auto for a fitted display or select a fixed 8-bit, 16-bit, 32-bit, or 64-bit boundary that matches the target integer, byte, word, or register.
Compare the decimal, binary, and hex outputs. The visualization distinguishes:
A dropped 1 means the fixed-width result has lost part of the unlimited mathematical value.
A bitwise left shift moves every integer bit toward the most significant side and fills the vacated low positions with zeros. C, C++, Java, and Python write the left shift operator as <<.
Live 8-Bit Left Shift
An 8-bit shift of decimal 23 by one position is:
00010111 << 1 = 00101110
23 x 2 = 46
Every bit moves one column left and the new least significant bit (LSB) becomes 0. Logical and arithmetic left shift have identical movement. Logical right shift and arithmetic right shift differ because a right shift must choose zero fill or sign extension.
When no significant bit is discarded:
A << n = A x 2^n
For an unsigned fixed-width result:
result = (A x 2^n) mod 2^width
For example, (240 x 2) mod 256 = 224, so 240 << 1 is 224 in an 8-bit field. Python defines left shift as multiplication by 2^n because Python integers use arbitrary precision.
Calculate A << n in five steps:
Manual Calculation Checker
A to binary.n positions.n zeros on the right.Example:
13 decimal = 00001101 binary
00001101 << 2 = 00110100 binary
Result = 52 decimal = 0x34
The arithmetic check is 13 x 2^2 = 52. Use the interactive checker to compare unlimited multiplication with the selected fixed width.
Each hex digit represents four binary bits. A four-position left shift therefore appends one zero hex digit when the selected width has enough room.
Left Shift Example Switcher
00000101<< 200010100200x2D<< 30x016836011110000<< 111100000224 (8-bit)| Expression | Input pattern | Result pattern | Decimal | Hex | Width |
|---|---|---|---|---|---|
1 << 1 | 00000001 | 00000010 | 2 | 0x02 | 8-bit |
5 << 2 | 00000101 | 00010100 | 20 | 0x14 | 8-bit |
16 << 2 | 00010000 | 01000000 | 64 | 0x40 | 8-bit |
1 << 7 | 00000001 | 10000000 | 128 | 0x80 | 8-bit unsigned |
0x2D << 3 | 0000000000101101 | 0000000101101000 | 360 | 0x0168 | 16-bit |
240 << 1 | 11110000 | 11100000 | 224 | 0xE0 | 8-bit overflow |
Most incorrect results come from four mistakes: using the wrong width, ignoring discarded bits, mixing signed and unsigned values, or passing an invalid count.
Bit Width and Overflow Checker
Python retains every significant bit, so 255 << 8 equals 65280. A fixed-width calculation retains only the low w bits. Select the same width as the target data type or register before comparing results.
A high bit that crosses the width boundary is discarded. A dropped 1 changes the fixed-width value; a dropped 0 does not. Carry-out reports a bit leaving an unsigned field, while signed overflow asks whether the result fits the signed range.
The 8-bit pattern 10000000 is unsigned 128 or signed -128 in two’s complement. Left-shift movement is the same for both interpretations, but language rules for signed overflow differ. Use unsigned operands for portable masks, packed fields, and register manipulation.
Use an integer count from 0 to width - 1 when matching C or C++. A negative or excessive count has undefined behavior in those languages. SEI CERT rule INT34-C recommends checking the count before shifting. Binary input accepts only 0 and 1; hexadecimal accepts 0-9 and A-F.
C and C++ use value << count for built-in integer left shift. Use unsigned types when the intended behavior is bit positioning.
Programming Language Shift Rules
uint32_t result = value << count;Check count < 32 and unsigned overflow before shifting.int result = value << count;An int uses the low five bits of the shift count.result = value << countIntegers use arbitrary precision and reject a negative count.#include <cstdint>
std::uint32_t flag = std::uint32_t{1} << 5; // 0x20
std::uint32_t field = std::uint32_t{5} << 8; // 0x500
1 << 5 creates a mask for bit five. 5 << 8 positions a value in bits eleven through eight. Microsoft’s C++ reference confirms that left shift zero-fills vacated positions and discards shifted-out bits.
Check the shift count and unsigned overflow before shifting:
bool can_shift(std::uint32_t value, unsigned count) {
return count < 32 && value <= (UINT32_MAX >> count);
}
Do not rely on an x86 or ARM CPU masking an invalid count. The C or C++ abstract machine can treat the source expression as undefined before compiler optimization produces a CPU instruction.
Left shift is mainly used to create masks, position packed fields, and prepare register or protocol values.
Register and Protocol Field Positioner
Create a one-bit mask with 1 << n, then use bitwise OR (|) to set it, AND (&) to test it, or XOR (^) to toggle it.
uint32_t ready_mask = UINT32_C(1) << 6;
flags |= ready_mask;
Shift each field to its assigned offset and mask source values so they cannot overwrite adjacent fields:
RGBA = ((red & 0xFF) << 24) |
((green & 0xFF) << 16) |
((blue & 0xFF) << 8) |
(alpha & 0xFF)
The same pattern is used for color channels, network protocol headers, and embedded-system data.
Registers use shifts to place control values at documented bit offsets. Graphics and network code use shifts for pixel channels, flags, lengths, and message types. Secure Hash Algorithm (SHA) and Advanced Encryption Standard (AES) implementations combine shifts with XOR and rotations; a left shift is not a circular rotate because discarded bits do not re-enter.
Direct answers about left-shift behavior, discarded bits, integer inputs, and performance.