get the lowest 10 bits from 32 bit number

I have this 32 bit value 2336227984 and i need to get the lowest 12 bits and convert from binary to a value. I also need to do the same thing with the highest 10 bits.

I have tried decbin() and I have tried pack/unpack … I have even tried additional functions like BCDEC2Bin/BCBin2Dec

I have been converting the value to binary, then taking the first 12 character, then converting it back from binary.

I have had no success. numbers are returned, but not the right numbers.

can you guys point me in the right direction?

So they start in binary or you need to convert them. Considering your data now is not binary data?

astonecipher is right, what format are they currently in?

If this is a string, just cut out what you need with text commands.
If it is a decimal code it can be tricky depending on the decimal formatting you are using.
(Decimal format of 10,2 would be 10 numbers, two decimal places, etc.)
If it is a binary number, then you can hack off the number of bits you want with binary commands…
if it is a posted entry on a web page, it is a string value.

Help us help you…

One more comment.

If it is truly a full 32 bit number, you can just AND it to clear out parts using binary ANDS.

Your 32 bit number is something like 0x8B400290 in hexidecimal…

So, if your number, lets say is
$number = &8B400290;
and you want the first half of it, just AND it using the " | " character with FFFF0000
which will erase the last for hexidecimal values…

Did that make sense? So, again, what are your numbers really stored as?

Sponsor our Newsletter | Privacy Policy | Terms of Service