News for hackers. Stuff that matters.
Re:Low Level Bit Hacks You Absolutely Must Know by notaddicted on Tuesday June 30, 2009 @03:19PM (#681371)
I was expecting to see "None of them" as kind of a joke.

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.

Re:Low Level Bit Hacks You Absolutely Must Know by CodeMage on Tuesday June 30, 2009 @03:53PM (#681450)
Maybe I'm missing something... Why the assumption that all (or even the majority of) HN readers are interested only in developing web apps?
Re:Low Level Bit Hacks You Absolutely Must Know by kscaldef on Tuesday June 30, 2009 @06:03PM (#681682)
It suffices that just one such individual exists to invalidate the claim of the title.
Re:Low Level Bit Hacks You Absolutely Must Know by yters on Tuesday June 30, 2009 @04:32PM (#681520)
Quick, someone bring more koolaid!
Re:Low Level Bit Hacks You Absolutely Must Know by piramida on Tuesday June 30, 2009 @04:23PM (#681510)
for a non-php developer that article is kind of trivial entry level stuff so no value either.
Re:Low Level Bit Hacks You Absolutely Must Know by paulgb on Tuesday June 30, 2009 @03:35PM (#681411)
I assume the title was targeted at Peteris' normal audience, not web app developers.

From the about: Peteris Krumins’ blog about programming, hacking, software reuse, software ideas, computer security, google and technology.

Re:Low Level Bit Hacks You Absolutely Must Know by notaddicted on Tuesday June 30, 2009 @05:14PM (#681596)
The purpose of the Hacker News website is to serve past/present/future ycombinator candidates. I'm not even a web app developer, I wrote C code for an $8 processor today.

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

Re:Low Level Bit Hacks You Absolutely Must Know by noodle on Tuesday June 30, 2009 @03:44PM (#681429)
not all of us here are (purely/originally) web app developers.
Re:Low Level Bit Hacks You Absolutely Must Know by jf on Tuesday June 30, 2009 @03:43PM (#681424)
Yes, even for web applications, bitwise manipulation will come in handy at some point.

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.

Re:Low Level Bit Hacks You Absolutely Must Know by notaddicted on Tuesday June 30, 2009 @03:57PM (#681461)
lol.

in python: (2 ^ 32)*upper + lower

edit: dbl star goes blank .. so in almost python

Re:Low Level Bit Hacks You Absolutely Must Know by tptacek on Tuesday June 30, 2009 @04:41PM (#681540)
You're XORing 32 into 2, multiplying it by the top word, and adding the bottom word?

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.

Re:Low Level Bit Hacks You Absolutely Must Know by comatose_kid on Tuesday June 30, 2009 @05:13PM (#681594)
Surprisingly (I just benchmarked it myself), the times are near the same.

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...
Re:Low Level Bit Hacks You Absolutely Must Know by tptacek on Tuesday June 30, 2009 @09:16PM (#681926)
That's surprising; it's more than twice as slow in Ruby (yeah, yeah). It's also (for obvious reasons) orders of magnitude faster in C --- if you were crazy enough to actually write code that way.
Re:Low Level Bit Hacks You Absolutely Must Know by ramchip on Wednesday July 01, 2009 @10:08AM (#682647)
I don't know much about Python so forgive me if this is stupid - but could 2^32 have been optimized as a constant, so that the result is just a multiplication and an addition?
Re:Low Level Bit Hacks You Absolutely Must Know by notaddicted on Tuesday June 30, 2009 @05:03PM (#681576)
Okay okay ... I should have written:

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.

Re:Low Level Bit Hacks You Absolutely Must Know by jf on Tuesday June 30, 2009 @04:55PM (#681559)
I considered that solution. And in thinking about why I chose to do bit-shifting, I remembered why: I actually needed to combine two _signed_ 32 bit integers in MySQL, and since I wasn't sure how signed integers are stored in MySQL, I figured that I could just use bit-shifting and move on.
Re:Low Level Bit Hacks You Absolutely Must Know by strlen on Wednesday July 01, 2009 @03:46AM (#682256)
Here's an example where a web developer may find bit=fiddling useful:

- 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).

Re:Low Level Bit Hacks You Absolutely Must Know by jackowayed on Tuesday June 30, 2009 @03:27PM (#681390)
same here! I was hoping it would just have the title and then be a blank page.