返回 2026-05-12
⚙️ 工程

逆位移操作:右移后再左移无法完全恢复原序列Inverse shift

johndcook.com·2026-05-11 节选正文

John D. Cook 探讨了二进制序列位移操作的不可逆性问题。以八位序列 abcdefgh 为例,右移一位得 0abcdefg,再左移一位却变为 abcdefg0,原始末尾字符 h 永久丢失。这说明简单的左移并不能作为右移的可靠逆运算。该现象揭示了数字信号处理中边界处理的重要性,尤其在循环缓冲区或编码理论中需特别注意数据完整性。

John

What is the inverse of shifting a sequence to the right? Shifting it to the left, obviously.

But wait a minute. Suppose you have a sequence of eight bits

abcdefgh

and you shift it to the right. You get

0abcdefg.

If you shift this sequence to the left you get

abcdefg0

You can’t recover the last element h because the right-shift destroyed information about h.

A left-shift doesn’t fully recover a right-shift, and yet surely left shift and right shift are in some sense inverses.

Yesterday I wrote a post about representing bit manipulations, including shifts, as matrix operators. The matrix corresponding to shifting right by k bits has 1s on the kth diagonal above the main diagonal and 0s everywhere else. For example, here is the matrix for shifting an 8-bit number right two bits. A black square represents a 1 and a white square represents a 0.

This matrix isn’t invertible. When you’d like to take the inverse of a non-invertible matrix, your kneejerk response should be to compute the pseudoinverse. (Technically the Moore-Penrose pseudoinverse. There are other pseudoinverses, but Moore-Penrose is the most common.)

As you might hope/expect, the pseudoinverse of a right-shift matrix is a left-shift matrix. In this case the pseudoinverse is simply the transpose, though of course that isn’t always the case.

If you’d like to prove that the pseudoinverse of a matrix that shifts right by k places is a matrix that shifts left by k places, you don’t have to compute the pseudo inverse per se: you can verify your guess. This post gives four requirements for a pseudoinverse. You can prove that left shift is the inverse of right shift by showing that it satisfies the four equations.

需要完整排版与评论请前往来源站点阅读。