Tico@PT Posted November 27, 2007 at 05:38 PM Report Share #150710 Posted November 27, 2007 at 05:38 PM Boas pessoal. Gostaria de saber se alguém já fez alguma coisa relacionada com a manipulação de bits em PHP. Estive a dar uma vista de olhos nas funções http://pt.php.net/pack e http://pt.php.net/manual/en/function.unpack.php mas não percebi muito bem como é que aquilo funciona... Help needed... ? Obrigado. Cumprimentos, Tico@PT aka pongz79 Link to comment Share on other sites More sharing options...
Gurzi Posted November 28, 2007 at 06:59 PM Report Share #151010 Posted November 28, 2007 at 06:59 PM Coloca a dúvida que tens de uma forma mais aprofundada, qual o real exemplo e qual o erro lógico ou de syntax que estás a obter. Ficamos à espera! Cumps Link to comment Share on other sites More sharing options...
Tico@PT Posted November 28, 2007 at 07:06 PM Author Report Share #151013 Posted November 28, 2007 at 07:06 PM Problema resolvido. Procurei no manual do php e encontrei lá as soluçoes 😁 function decextbin($decimalnumber,$bit) { $maxval = 1; $sumval = 1; for($i = 1; $i < $bit; $i++) { $maxval = $maxval * 2; $sumval = $sumval + $maxval; } if ($sumval < $decimalnumber) { return 'ERROR - Not enough bits to display this figure in binary.'; } for($bitvalue = $maxval; $bitvalue >= 1; $bitvalue = $bitvalue / 2) { if (($decimalnumber / $bitvalue) >= 1) { $thisbit = 1; } else { $thisbit = 0; } if ($thisbit == 1) { $decimalnumber = $decimalnumber - $bitvalue; } $binarynumber .= $thisbit; } return $binarynumber; } em conjunto com: http://pt2.php.net/decbin, http://pt2.php.net/bindec, http://pt2.php.net/pack e http://pt2.php.net/unpack. Cumps Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now