Quantcast
Channel: Create a mask that marks the most significant set bit, using only bitwise operators - Stack Overflow
Browsing latest articles
Browse All 6 View Live

Answer by stephann for Create a mask that marks the most significant set bit,...

assign a_reversed = {<<{a}}; assign a_2s_compl = (~a_reversed) + 1'b1; assign a_lsb_set = a_reversed & a_2s_compl; assign a_msb_set = {<<{a_lsb_set}}; This could all be done in one line...

View Article



Answer by Brave Sir Robin for Create a mask that marks the most significant...

In fact, you can use the second algorithm mentioned there, with a slight modification: In the special case of b being of the form 0n1m (a > b) == !!(a & ~b) holds.

View Article

Answer by rywhite for Create a mask that marks the most significant set bit,...

I'm still interested to see what other people can come up with, but a friend has figured out the answer. int greatestBitPos(int x) { int a = x | (x >> 1); a = a | (a >> 2); a = a | (a...

View Article

Answer by Lynn for Create a mask that marks the most significant set bit,...

Fill all of the bits to the right of the most significant one by shifting and OR'ing: 0b 0010 0000 0000 0000 0100 0000 0000 0000 0b 0011 0000 0000 0000 0110 0000 0000 0000 0b 0011 1100 0000 0000 0111...

View Article

Answer by Floris for Create a mask that marks the most significant set bit,...

Updated to work for negative numbers (assuming that this should return 0x80000000 since these numbers have their top bit set ) int gbp(int n) { // return log(2) of n unsigned int m; m = n; m = m | m...

View Article


Create a mask that marks the most significant set bit, using only bitwise...

This was part of a larger programming assignment that was due for me last night. Couldn't figure out this problem, but I'm curious as to how it could be solved. The function int greatestBitPos(int x)...

View Article
Browsing latest articles
Browse All 6 View Live




Latest Images