Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

I don\'t really understand bit-wise operators. I understand what ^,|,&,<<,>> and

ID: 3564577 • Letter: I

Question

I don't really understand bit-wise operators.

I understand what ^,|,&,<<,>> and ~ do separately in basic functions, but more complex problems about bit-wise operators confuse me.

1) Given that x is an integer, write an expression that would give an integer that corresponds to the last 4 bits of x.

2) Assuming that x is an integer, write an expression that would give an integer that corresponds to the next 4 bits of x. (the bits that correspond to the positions with values 2^4, 2^5, 2^6 and 2^7).

Thanks!

Explanation / Answer

Bitwise operators are used to perform operations on binarydata.

First you need to convert Decimal data int Binary.

Example

take int i=4;

4 Equalent Decimal value is 0100

3 Equalent Decimal value is 0011

"^" operator is Bitwise Exclusive oR operator

it performs" ^" operation on 3 and 4

0100   -----4

0011    ------3

--------------------------------------

0111        -------6 -------Result

means if expression in coulmn wise it contains even single 1 in expression result is 1 other wise result is 0

See bitwise "^" example

1^0(Both 1 and 0 are bi wise)

it gives expression like (a'b+b'a);

subtuting values in expression(01'+1'0)     //Here " ' " it is complement , 0 complement means 1 and one complete is 0;