cancel
Showing results for 
Search instead for 
Did you mean: 

Archives Discussions

spectral
Adept II

Extract bits from int

Hi,

I'm working on a radix-sort algorithm and I need to extract some bits from int values.

My sort is working fine when I sort on 4,12,20,24,28,32 bits but not on 8 and 16 bits !!!!

I don't understand the reason, maybe a problem with the way I extract the bits !

I use the following :

#define EXTRACT_BIT(VALUE,BIT) ((((uint)VALUE)>>BIT)&0x1)

#define EXTRACT_4BITS(VALUE,BIT) ((((uint)VALUE)>>BIT)&0x0F)



Do you have an advice ?

0 Likes
2 Replies
Meteorhead
Challenger

I do not know why that does not work. In the meantime you can try:

#define EXTRACT_BIT(VALUE,BIT) (((uint)VALUE << (uint)(BIT)) >> 31u )

#define EXTRACT_4BITS(VALUE,BIT) (((uint)VALUE << (uint)(BIT)) >> 17u )

0 Likes

Thanks Meteor Head,

Strangely I have the same problem !

0 Likes