r/javaTIL • u/karlthepagan • Jun 20 '15
TIL the inverse of left shift
inb4 "the opposite is right shift"
given:
x = 1 << y;
expect:
y == 31 - Integer.numberOfLeadingZeros(x);In C this is usually the clz function.
6
Upvotes
View all comments
Show parent comment
1
u/karlthepagan Oct 16 '15
That's opposite not the inverse function. Saw this coming.
Implement f.