Skip to content

Reverse Bits#148

Open
tom4649 wants to merge 2 commits into
mainfrom
190.Reverse-Bits
Open

Reverse Bits#148
tom4649 wants to merge 2 commits into
mainfrom
190.Reverse-Bits

Conversation

@tom4649

@tom4649 tom4649 commented Jul 12, 2026

Copy link
Copy Markdown
Owner

Comment thread 0190.Reverse-Bits/memo.md
## step2
https://github.com/Kitaken0107/GrindEasy/pull/23

> 文字列に変換しないでやってみてください。ビット操作の問題だと思います。

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ループで回してもいいですが、ビットマスクで隣同士のビットを入れ替えられますね。2ビットずつも入れ替えられますね。
また __builtin_bitreverse32 が環境によってはあります。
8ビットのルックアップテーブルを用意して4回使う手もあるかもしれません。

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ルックアップテーブルは、昔はよく見たテクニックですが CPU が速くなってあまり見なくなりましたね。

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

昔と比べて1000倍ほど速くなっているようですね。今のCPUのクロック数が3~6Ghzあたりというのは覚えておこうと思います。
https://en.wikipedia.org/wiki/List_of_Intel_CPU_microarchitectures

Comment thread 0190.Reverse-Bits/memo.md
,,2a,,
```

bit演算でも書く。

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

分割統治法で解く方法もあります。興味があれば探してみて下さい。ソフトウェアエンジニアの常識には含まれていないと思いますが、「ハッカーのたのしみ」に書かれており、これを読んだソフトウェアエンジニアなら知っていると思います。
https://www.amazon.co.jp/%E3%83%8F%E3%83%83%E3%82%AB%E3%83%BC%E3%81%AE%E3%81%9F%E3%81%AE%E3%81%97%E3%81%BF%E2%80%95%E6%9C%AC%E7%89%A9%E3%81%AE%E3%83%97%E3%83%AD%E3%82%B0%E3%83%A9%E3%83%9E%E3%81%AF%E3%81%84%E3%81%8B%E3%81%AB%E3%81%97%E3%81%A6%E5%95%8F%E9%A1%8C%E3%82%92%E8%A7%A3%E3%81%8F%E3%81%8B-%E3%82%B8%E3%83%A5%E3%83%8B%E3%82%A2-%E3%83%98%E3%83%B3%E3%83%AA%E3%83%BC%E3%83%BBS-%E3%82%A6%E3%82%A9%E3%83%BC%E3%83%AC%E3%83%B3/dp/4434046683

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(pushするのを忘れていました。)
この解法は自分では全く思いつきませんでした。「ハッカーのたのしみ」はビット演算について詳しく書かれた本のようですね。機会があれば手に取ってみようと思います。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants