Reputation: 10249
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
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