A

Arpit Jain Post on 21/01/2019

Y

Instructor

Yogesh Chawla Reply on 22/01/2019Integer.toString(100,8) // prints 144 --octal representation

Integer.toString(100,2) // prints 1100100 --binary representation

Integer.toString(100,16) //prints 64 --Hex representation

or you can also do like this

Integer.toBinaryString(x) for binary number representation

Bitwise Algorithm/Data Structure is used to perform operations at bit-level.

Bitwise operator used to work on bits there by performing bit-by-bit operation.

Operator Description Example

& Bitwise AND Operator will result 1 if both the bits are 1. A & B

| Bitwise OR Operator will result in 1 if either both the bits are 1 of any of the one bit is 1 . A | B

^ Bitwise XOR Operator results in 1 if one of the bits is 1 but not both. A ^ B

~ Bitwise Complement will 'flip' bits resulting 0 in 1 and 1 in 0. ~A

<< Bitwise Left Shift Operator will shift the bits specified to left A << 2

>> Bitwise Right Shift Operator will shift the bits specified to right. A >> 2

Bitwise AND operation of two integers 13 and 24.

13 = 00001101 (In Binary)

24 = 00011000 (In Binary)

00001101

&00011000

----------

00001000(8 is the answer in decimal)

Bitwise XOR Operation of 13 and 24

00001101

|00011000

----------

00010101(21 is the answer in decimal)

Shift Operators: There are two bit shifting operators

Right Shift Operator

13 = 00001101 (In Binary)

13>>3 = 00000001 (In binary) [Right shifting bits by three bits]

Left Shift Operator

13 = 00001101 (In Binary)

13<<2 = 00110100(In binary) [left shifting bits left by two bit]

13<<0 =00001101 (Shift by 0)

We have used this term while explaining primitive data types in java programming language regarding how each and every number or a word is saved in

memory becuase bit manipulation is the process of manipulating bits which is used to represent some word in memory.

Bit manipulation requires low level programming as we are completely working on the bits i.e 0,1.