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
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).

Link to comment
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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.