TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

Absolute Beginner's Guide to Bit Shifting

101 pointsby ksetyadiabout 13 years ago

4 comments

jiggy2011about 13 years ago
Beyond OS kernels , drivers and embedded systems is there any real use for this?<p>I only ask because we were never taught about bit shifting at university and I can't think of a time where it would have ever been useful in my work but despite this it seems to be a very common thing to ask about at interviews so I have sort of educated myself about it for that reason alone.
评论 #3664233 未加载
评论 #3664779 未加载
评论 #3665012 未加载
评论 #3664175 未加载
评论 #3663881 未加载
评论 #3665110 未加载
评论 #3665132 未加载
riledhelabout 13 years ago
Please don't read just the selected answer, because he got the optimizations wrong. Bit shifting operations are always faster than multiplications (as the guy with the second most voted answer explains).
评论 #3663355 未加载
评论 #3664460 未加载
评论 #3663304 未加载
评论 #3663657 未加载
swordswinger12about 13 years ago
This could've helped me last week. I was pulling my hair out debugging a CUDA implementation of the SHA3 candidate BLAKE, and after a full week of debugging the same 70 lines (and one complete rewrite) the issue turned out to be most-significant-bit padding with arithmetic right shifts. I just changed every 'char' type to 'uint8_t' and the code worked perfectly.
hackermomabout 13 years ago
In machine code language, we refer to these as rotating and shifting, instead of "shifting and non-circular shifting".