apaci / bithacks.h Goto Github PK
View Code? Open in Web Editor NEWThis project forked from pkrumins/bithacks.h
bithacks.h is a C header file containing useful bit manipulation macros
Home Page: http://www.catonmat.net/blog/bit-hacks-header-file/
This project forked from pkrumins/bithacks.h
bithacks.h is a C header file containing useful bit manipulation macros
Home Page: http://www.catonmat.net/blog/bit-hacks-header-file/
This is "bithacks.h" C header file and it contains various macros for bit manipulations. It's accompanied with "bithacks-test.c", which tests all the macros. It was written by Peteris Krumins ([email protected]). His blog is at http://www.catonmat.net -- good coders code, great reuse. The code is licensed under the MIT license. The code was written as a part of the article "bithacks.h - bit hacks header file" on my website. The whole article can be read at: http://www.catonmat.net/blog/bit-hacks-header-file/ ------------------------------------------------------------------------------ Table of contents: [1] Macros in bithacks.h file [2] The test program bithacks-test.c [1]-Macros-in-bithhacks.h-file------------------------------------------------ The "bithacks.h" header provides the following macros: * B8(x) - turns x written in binary into decimal, * B_EVEN(x) - tests if x is even (bithack #1), * B_ODD(x) - tests if x is odd (inverse of (bithack #1)), * B_IS_SET(x, n) - tests if n-th bit is set in x (bithack #2), * B_SET(x, n) - sets n-th bit in x (bithack #3), * B_UNSET(x, n) - unsets n-th bit in x (bithack #4), * B_TOGGLE(x, n) - toggles n-th bit in x (bithack #5), * B_TURNOFF_1(x) - turns off the right-most 1-bit in x (bithack #6), * B_ISOLATE_1(x) - isolates the right-most 1-bit in x (bithack #7), * B_PROPAGATE_1(x) - propagates the right-most 1-bit in x (bithack #8), * B_ISOLATE_0(x) - isolates the right-most 0-bit in x (bithack #9), * B_TURNON_0(x) - turn on the right-most 0-bit in x (bithack #10). [2]-The-test-program-bithacks-test.c------------------------------------------ The test program "bithacks-test.c" tests all the macros above. You have to first compile it: $ gcc bit-hacks-test.c -o bithacks-test This will create the "bithacks-test" program. Now run it to verify all the bithacks in bithacks.h: $ ./bithacks-test All tests OK. ------------------------------------------------------------------------------ I explained all the bithacks in bithacks.h in another article "Bit Hacks You Absolutely Must Know About": http://www.catonmat.net/blog/low-level-bit-hacks-you-absolutely-must-know/ Also see the original article on bithacks.h "bithacks.h - bit hacks header file": http://www.catonmat.net/blog/bit-hacks-header-file/ ------------------------------------------------------------------------------ That's it. Happy bithacking! Sincerely, Peteris Krumins http://www.catonmat.net
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.