Help please! Most programming languages provide operations, called bit-wise oper
ID: 3587415 • Letter: H
Question
Help please!
Most programming languages provide operations, called bit-wise operations that allow the user to manipulate the bits of signed or unsigned integers. The following list shows some of the bit opcrations which are available in Java and C. The variables x, y and i represent integers (signed or . denotes the integer whose i-th bit is the complement of the i-th bit of x. That is, the i-th bit of -x is 0 if the i-th bit of x is1 and it is 1 otherwise. For instance, assuming that we have 8-bit integers, then 511,-001 100112, and-51 = 1 1001 100 x & y denotes the integer whose i-th bit is the logical AND of the i-th bit of x and the i-th bit of y. For instance, assuming that we have 8-bit integers, 10910-011011012 and 5110 001 1001 12, then 109 & 51 = 001000012 = 3310. x/ y denotes the integer whose i-th bit is the logical OR of the i-th bit of x and the i-th bit * · x ^ y denotes the integer whose i-th bit is the logical XOR of the i-th bit of x and the i-th bit of y. For instance, 109 ^ 51 = 01 01 1 1 102 x >> 3 00001 101 = 1310 (the last 3 bits 101 were removed and 3 0s added at the We can perform several operations by manipulating the sequence of bits that represents an integer using these operators. In this problem, we look at some of them (if you need to, assume that a) There are several situations where we would like to retain only some of the bits of an write an expression that would give an integer that corresponds to the last 4 bits of x. b) Now, assuming that x is an integer, write an expression that would give an integer that integers are represented by 32 bits using two's complement. integer x. For instance, the last 3 bits of 109 equal 101 51o. Given that x is an intege, corresponds to the next 4 bits ofx, i.e. the bits that correspond to the positions with values 24,25,2 and 2 c) Ifx is any integer, what is the result of the following operations? iv. . vi. xExplanation / Answer
a) 109 in binary is 01101101
Last 4 bits : 01101101 & 0x0F
=> let x BE THE VARIABLE CONTAINING 109 , So ( x & 0x0F) will give us the value of last 4bits
b) First 4 bits ,
( ( x >>4 )& 0x0F )
Right SHift by 4 bits and bIT WISE AND with 0000 1111
c)i) x^x = 0
II) x &x = x
III) x | x = x
iv) x<<2 =
x = x*4 = 4x i.e Some bits 11
v) >>> is unsigned right shift i.e insert zero to left
Some bits 00
vi) 2s complement of number
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.