# Thread: How do I get the lower 12 bits of a 32 bit int?

1. ## How do I get the lower 12 bits of a 32 bit int?

How do I get the lower 12 bits of a 32 bit int?

2. It probably depends on how you want it. Perhaps you could use:
Code:
`std::bitset<12> bits(num);`

3. Originally Posted by Yarin
How do I get the lower 12 bits of a 32 bit int?
val & 0xFFF

4. __asm AND val , 0x00000FFF

5. abachler, why use your solution when brewbuck's suggestion works fine (assuming Yarin wants the bits in that way) and is more portable?

6. >> assuming Yarin wants the bits in that way

Here is why I'm trying to get the 16 bits.
The channel handle :
The return value is reference counted. This stops the user from updating a stolen channel.
Basically it means the only sound you can change the attributes (ie volume/pan/frequency/3d position) for are the one you specifically called playsound for. If another sound steals that channel, and you keep trying to change its attributes (ie volume/pan/frequency/3d position), it will do nothing.
This is great if you have sounds being updated from tasks and you just forget about it.
You can keep updating the sound attributes and if another task steals that channel, your original task wont change the attributes of the new sound!!!
The lower 12 bits contain the channel number. (yes this means a 4096 channel limit for FMOD
The upper 19 bits contain the reference count.
The top 1 bit is the sign bit.
ie
S RRRRRRRRRRRRRRRRRRR CCCCCCCCCCCC
So will 0xFFF work fine in doing that job?

7. Originally Posted by Yarin
>> assuming Yarin wants the bits in that way

Here is why I'm trying to get the 16 bits.

So will 0xFFF work fine in doing that job?
Yes.

8. If you want to extract a certain number of bits from a string, then the general method is this:
Open your calculator, switch to binary mode, enter n 1 then convert to decimal or hexdecimal.
Then simply do a binary AND with the mask on the original number and you have extracted n bits.
(Binary 1111 1111 1111 is hex 0xFFF)

9. Right, okay it's working, thanks.