Beginner

位元移位計算器(左移與右移)

將整數向左或向右移動所選位元數,在固定位元寬度內以十進制、二進制和十六進制查看結果。
Decimal integer; negatives use two's complement in the bit width
Number of bit positions to shift

換算方向

Right-shift type

Only applies to right shifts

bits

Result wraps to this many bits
Shifted value (decimal)
168

n << 2 = 10101000 (0xA8)

Binary (w-bit)
10101000
Hexadecimal
0xA8
Signed decimal
-88
Bits vacated/filled
2 (filled with 0)
Bits dropped
2 (0)
031.963.895.6127.5159.4191.3223.1255Value before and after shift in the 8-bit range
Step by step
  1. 1

    Mask n to 8 bits

    42 & (256 − 1) = 42
  2. 2

    n × 2^2 (mod 2^8)

    (42 × 4) mod 256 = 168
    A left shift by k is equivalent to multiplying by 2^k within the bit width.
計算結果僅為一般資訊用途的估算值,並非專業建議——在仰賴重要結果之前,請務必自行獨立查證。 閱讀完整免責聲明.
快速解答

此計算機如何運作?

左移將位元向高端移動並在右側填充零;右移將位元向低端移動。邏輯右移在左側填充零,而算術右移複製符號位元。結果遮罩到所選位元寬度,並以十進制、二進制和十六進制顯示。

公式
Left: r = (n << k) & mask; Logical right: r = (n & mask) >> k; Arithmetic right: sign bit replicated into the top k positions (mask = 2^w - 1)
How this is calculated

您提供整數 n、移位量 k、方向(左或右)、右移類型(邏輯或算術)以及位元寬度 w。所有算術使用任意精度整數,然後用 mask = 2^w - 1 約束到 w 位元。輸入首先被縮減到其 w 位元模式,因此負值以二補數表示。

左移計算 (n << k) & mask:每個位元向最高有效端移動 k 個位置,低 k 個位置填充零,任何移過寬度頂端的位元溢出並被丟棄。邏輯右移計算 (n & mask) >> k:位元向最低有效端移動 k 個位置,低 k 位元被丟棄,頂部 k 個位置填充零。算術右移的行為相同,但空出的頂部 k 個位置填充原始符號位元(MSB)的副本,從而保持二補數數字的符號。

結果以無號十進制、零填充的 w 位元二進制字串和十六進制顯示,並加上有號二補數解釋。移位量 k 大於或等於 w 時,左移和邏輯右移產生 0,算術右移根據符號位元產生全 1 或全 0 的模式。負 k 被拒絕。

常見問題

邏輯右移始終在空出的高位元中填充零,將值視為無號數。算術右移將符號位元(最高有效位元)複製到這些位置,保持符號以使負二補數數字保持負值。

結果遮罩到所選位元寬度。移過最高有效位置的位元溢出並被丟棄,因此在固定寬度內,左移可能繞回到較小的值。

負 n 在移位前被轉換為其 w 位元二補數模式。輸出顯示該模式的無號十進制和有號十進制解釋。

也稱為

位元移位
左移右移
邏輯移位
算術移位
bit shift
移位運算
位元位移
shift

APA

TG we-Calculate Editorial Team. (2026). 位元移位計算器(左移與右移) [Online calculator]. TG we-Calculate. https://we-calculate.com/zh-tw/calculator/bit-shift-calculator

Chicago

TG we-Calculate Editorial Team. "位元移位計算器(左移與右移)." TG we-Calculate. 2026. https://we-calculate.com/zh-tw/calculator/bit-shift-calculator.

IEEE

TG we-Calculate Editorial Team, "位元移位計算器(左移與右移)," TG we-Calculate, 2026. [Online]. Available: https://we-calculate.com/zh-tw/calculator/bit-shift-calculator

BibTeX

@misc{wecalculate_bit_shift_calculator, title = {位元移位計算器(左移與右移)}, author = {{TG we-Calculate Editorial Team}}, howpublished = {\url{https://we-calculate.com/zh-tw/calculator/bit-shift-calculator}}, year = {2026}, note = {TG we-Calculate} }

這個計算機對您有幫助嗎?