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
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started