Bit conversion operations in PHP

Posted by Goro on Stack Overflow See other posts from Stack Overflow or by Goro
Published on 2010-06-01T16:47:04Z Indexed on 2010/06/01 16:53 UTC
Read the original article Hit count: 188

Filed under:
|
|

Hello,

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

  • Being able to select and move individual bits in a variable
  • Being able to cast statically one type of variable to the other (ie. int to float)

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

  • there may already be a library in php that does this sort of thing
  • I would be better off with delegating the calculations to some other language

Thanks,

© Stack Overflow or respective owner

Related posts about php

Related posts about casting