Question: bitwise operation let say i have a 32bit signed int i i wanted to extract bit 7 to bit 13 as an integer v ((0x3F80

bitwise operation

let say i have a 32bit signed int i

i wanted to extract bit 7 to bit 13 as an integer v

((0x3F80 & i) << 18) >>25

this will get me the result. 0000 0000 0000 0000 0000 0000 0XXX XXXX

how is this gonna work? if bit 6 = 1, v is negative / if bit 6 = 0, v is positive

its still a 32 bit int and we have all the zeros before bit 6.

please explain and compare with the second answer below:

let u be the input signed integer

int u = (i & 0x00003F80) >> 7

if (u & 0x00000040)

u |= 0xFFFFFF80

this one = 1111 1111 1111 1111 1111 1111 1XXX XXXX (it has all ones before bit 6)

please explain both answers and the logic behind it

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!