From the about: Peteris Krumins’ blog about programming, hacking, software reuse, software ideas, computer security, google and technology.
The title (as submitted by the author of the blog) says "Absolutely Must Know," which is quite hyperbolic.
I would suggest: Basic tricks of bit manipulation.
Consider that this topic is covered in K. N. King's book C Programming: A Modern Approach, in Chapter 20: Low-Level Programming, on page 451
Personal anecdote: I recently had to combine two arbitrary unsigned 32 bit integers into one unsigned 64 bit integer to make a unique ID for an index. Not sure how I would have done that without bitwise manipulation.
in python: (2 ^ 32)*upper + lower
edit: dbl star goes blank .. so in almost python
Also, you think exponentiation and multiplication is faster than a shift and an OR? I think you're the target audience for this article, and I revise my opinion (thankfully unstated) about whether this is material every developer "must" know.
Here's my benchmark (in case I made a mistake):
import time
def combine(upper,lower): return (2**32)*upper + lower
def combine2(upper,lower): return (upper << 32) | lower
def test_combine():
start = time.clock()
for i in range(10000000):
combine(i,i)
end = time.clock()
output = 'The time taken for combine() is ' + str(end - start)
print output
def test_combine2():
start = time.clock()
for i in range(10000000):
combine2(i,i)
end = time.clock()
output = 'The time taken for combine() is ' + str(end - start)
print output
Also see http://wiki.python.org/moin/PythonSpeed/PerformanceTips#Pyth...import math; math.pow(2,32)
I tried to use the double star operator, but that is markup for italics in this software, so it was edited out.
- How would you, compactly and discretely, represent in a cookie the days on which a user has visited your site this month?
(I am decided not a web developer, but this is a question I'd ask a web developer on a phone screen were I to hire one).
For a web app developer are these useful? For fun? yes. For profit? no. Title should be Low Level Bit Hacks You May Find Interesting.