Goro
Goro

Reputation: 10249

Bit conversion operations in PHP

I find myself in need of performing bit-level conversion on variables in PHP. In more detail, I have a bit stream that is read as an integer by hardware, and I need to do some operations on the bits to make it into what its actually supposed to be (a float). I have to do this a few times for different formats, and the functionality I need is

I know php natively supports bitwise AND, OR, etc, and shift operations, but I was wondering if:

Thanks,

Upvotes: 2

Views: 680

Answers (3)

vartec
vartec

Reputation: 134631

For converting bit stream to whatever you need use unpack().

Once converted to integer, you can use bitwise operators. Note, that they don't support floats, so in case of float it'd first be casted to integer.

Upvotes: 0

baloo
baloo

Reputation: 7775

Is it pack and unpack that you want?

Upvotes: 2

Related Questions