Jump to content

Bitwise NOT?


kenchucky

Recommended Posts

I know that I can use & to see whether a bit is off or on, | to turn a bit on, ^ to toggle a bit, << to left shift and >> to right shift, but I can't figure out how to turn a bit off (bitwise NOT).

What is the command to do this in MySQL?

P.S. Also, what is it in PHP? And what is the bitwise XOR command in PHP? I tried ^ but is the command for power to (10^3==1000)

P.P.S How do I declare an unsigned 8 bit integer in PHP? (int) works for signed 32 bit, but I can't get (uint 8) to work.

Link to comment
https://forums.phpfreaks.com/topic/94358-bitwise-not/
Share on other sites

 

P.S. Also, what is it in PHP? And what is the bitwise XOR command in PHP? I tried ^ but is the command for power to (10^3==1000)

P.P.S How do I declare an unsigned 8 bit integer in PHP? (int) works for signed 32 bit, but I can't get (uint 8) to work.

 

First, let's kill your fallacy that ^ is the power operator in PHP

 

<?php
echo 10 ^ 3;        // 9
echo pow(10, 3);    // 1000
?>

 

Now,  XOR. You didn't try very hard, did you?

<?php
$a = 0xAA;
echo decbin($a);       // 10101010         (8 bits)

$b = 0xFF;
echo decbin($b);       // 11111111

$c = $a ^ $b;          // xor
echo decbin($c);       // 01010101

$d = $c ^ $b ;
echo decbin($d);       // 10101010
?>

Link to comment
https://forums.phpfreaks.com/topic/94358-bitwise-not/#findComment-483352
Share on other sites

That is where I found the ones that I listed.

I could not find the bitwise NOT operation on it.

 

Like 96 (NOT) 32 would become 64, and 64 (NOT) 32 would stay as 64.

 

The opposite of bitwise OR (64 | 32 becomes 96, and 96 | 32 stays 96).

 

SELECT 96 & ~32

--> 64

Link to comment
https://forums.phpfreaks.com/topic/94358-bitwise-not/#findComment-483376
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.