GithubHelp home page GithubHelp logo

bitwise-operators's Introduction

Introduction to Bitwise Operators

As name suggests, it does bitwise manipulation

  1. & = AND
  2. | = OR
  3. ~ = NOT
  4. << = Left Shift
  5. = Right Shift

  6. ^ = XOR

Bitwise AND (&) Operator

Result of AND is 1 when both bits are 1

7 & 4 = 4 0111 & 0100 = 0100

Truth Table

A B A&B
0 0 0
0 1 0
1 0 0
1 1 1

Bitwise OR (|) Operator

Result of OR is 0 when both bits are 0

7 & 4 = 4 0111 | 0100 = 0111

Truth Table

A B A&B
0 0 0
0 1 1
1 0 1
1 1 1

Bitwise NOT (~) Operator

Result of NOT is 0 when bit is 1 and 1 when bit is 0

~7 = 8 ~0111 = 1000

Truth Table

A ~A
0 1
1 0

Left Shift (<<) Operator

First operand << Second operand

First Operand: Whose bits get left shifted Second Operand: Decides the number of places to shift the bits

Trailing positions are filled with zeros

3 = 00000011 3<<1 = 00000110 = 6

Each left shift multiplies the original number by 2

Right Shift (>>) Operator

First operand << Second operand

First Operand: Whose bits get right shifted Second Operand: Decides the number of places to shift the bits

Leading positions are filled with zeros

3 = 00000011 3>>1 = 00000001 = 1

Each right shift divides the original number by 2

XOR (>>) Operator

Truth Table

Either A is 1 or B is 1 then the output is 1 but when both A and B are 1, then output is 0.

A B A XOR B
0 0 0
0 1 1
1 0 1
1 1 0

bitwise-operators's People

Contributors

dejagianelli avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.