Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why use a bitwise AND here?

I was reading through the hadoop code and found this line in a partitioner.

(key.hashCode() & Integer.MAX_VALUE) % numReduceTasks

Why are they using the bitwise AND?

like image 894
jshen Avatar asked Feb 05 '11 01:02

jshen


1 Answers

To remove the sign bit. in the case that the hashCode is a negative number. its like Math.abs(key.hashCode())

like image 131
The Scrum Meister Avatar answered Oct 19 '22 11:10

The Scrum Meister