Log in

View Full Version : Low Level Bit Hacks You Absolutely Must Know


taichichuan
21-10-2010, 11:14
For those software folks who are looking deeper into embedded systems development:

http://www.catonmat.net/blog/low-level-bit-hacks-you-absolutely-must-know

Enjoy,

Mike

RyanCahoon
21-10-2010, 14:04
Check out Hacker's Delight (http://www.hackersdelight.org/) for even more (crazy) bit hacking algorithms.

--Ryan

lynca
24-10-2010, 11:48
Thanks for sharing,

An embedded programming refresher is always useful especially with the growth of graphical programs that abstract away bit level details.

Greg McKaskle
25-10-2010, 12:07
Since they are based on discrete and Boolean mathematics, bit hacks are actually equally valid for LV and any language with rich numerical types and operators. It may not be obvious, but the Boolean operators in LV work on all integer types, and make for concise implementation of many of them.

If you like the general bit hacks and truly want to remember and use them well, I encourage you to try your hand at proofs for them. They don't have to be fully rigorous, but that is of course a useful thing to practice too.

Greg McKaskle

EricVanWyk
25-10-2010, 12:40
If any of my students use any of these bit hacks without commenting them, I will smack them.

Ether
25-10-2010, 12:46
If any of my students use any of these bit hacks without commenting them, I will smack them.

The first 3 deserve maybe only a noogie, don't you think?

EricH
25-10-2010, 12:56
Any programmer who doesn't comment his/her work, no matter the project, deserves to be deprived of caffeine for a week or more. If that doesn't do the trick, proceed to the harsher methods... like noogies and smacks with a mouse cord...

Taylor
25-10-2010, 13:04
Any programmer who doesn't comment his/her work, no matter the project, deserves to be deprived of caffeine for a week or more. If that doesn't do the trick, proceed to the harsher methods...

Isn't caffeine depravation pretty much the harshest method available? Programming is one application where "shoot first, ask questions later" may not apply.

artdutra04
25-10-2010, 15:17
If any of my students use any of these bit hacks without commenting them, I will smack them.But altering register values via bitwise operations in nested ternary commands is so much fun! :rolleyes:

EricVanWyk
25-10-2010, 17:27
But altering register values via bitwise operations in nested ternary commands is so much fun! :rolleyes:

Smack!

demosthenes2k8
25-10-2010, 18:16
artdura04, you're amazing. The only thing I can think to add to that is that it has to be done inside an obfuscated macro using a templated function pointer and several magic numbers.

Robototes2412
25-10-2010, 23:01
or you can be a super-meanie and use a classic turing-style method for making a hello world program, like I did:
#include <stdio.h>
int main(){char* p=new char[1024];++*p;++*p;++*p;++*p;++*p;++*p;++*p;++*p;++*p;++*p ;while(*p){++p;++*p;++*p;++*p;++*p;++*p;++*p;++*p; ++p;++*p;++*p;++*p;++*p;++*p;++*p;++*p;++*p;++*p;+ +*p;++p;++*p;++*p;++*p;++p;++*p;--p;--p;--p;--p;--*p;}++p;++*p;++*p;putchar(*p);++p;++*p;putchar(*p) ;++*p;++*p;++*p;++*p;++*p;++*p;++*p;putchar(*p);pu tchar(*p);++*p;++*p;++*p;putchar(*p);++p;++*p;++*p ;putchar(*p);--p;--p;++*p;++*p;++*p;++*p;++*p;++*p;++*p;++*p;++*p;++* p;++*p;++*p;++*p;++*p;++*p;putchar(*p);++p;putchar (*p);++*p;++*p;++*p;putchar(*p);--*p;--*p;--*p;--*p;--*p;--*p;putchar(*p);--*p;--*p;--*p;--*p;--*p;--*p;--*p;--*p;putchar(*p);++p;++*p;putchar(*p);++p;putchar(*p );return 0;}

its evil