Logical and Bitwise Not Operators on Boolean:

Many of the languages such as Java, C++, and Python have the flexibility of providing Boolean types which can be set to either TRUE or FALSE. Here we will be learing about it keeping in mind the python for data science view of it.

Let’s consider a program that uses Logical Not (or !) operator on Boolean.

python for data science

The example above is an expected one. But what will happen if we have not used Bitwise Not ( or ~) operator before? Let’s see through an example.

data science

The bitwise not operator ~ gives the complement of a number. So, 0 becomes 1, and vice versa. As we know, Boolean TRUE and FALSE values have values 1 and 0, respectively.

As it returns the inverse, so, TRUE will return inverse of 1 and FALSE will return inverse of 0.

Java- Java has no such function to attach ~ operator to Boolean values.

bitwise in data science

So, we can say that “Logical Not or !” is for Boolean values and “bitwise not or~” for integers. C/C++ and Python are into auto-promotion of Boolean to integer types when an integer operator is applied. But Java does no such thing.

If you want to learn more about bitwise operators in python for data science then you can check this and this.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.