R
rajm2019
Given two integers A & B. Determine how many bits required to convert
A to B.how to write a function int BitSwapReqd(int A, int B);
A to B.how to write a function int BitSwapReqd(int A, int B);
Given two integers A & B. Determine how many bits required to convert
A to B.how to write a function int BitSwapReqd(int A, int B);
"osmium said:The exclusive or operator may help you.
Why do I get the feeling someone has a homework assignment, and hasn't
been paying attention in class?
(CF his other post - "function to divide by three")
--
Don Bruder - (e-mail address removed) - If your "From:" address isn't on my whitelist,
or the subject of the message doesn't contain the exact text "PopperAndShadow"
somewhere, any message sent to this address will go in the garbage without my
ever knowing it arrived. Sorry... <http://www.sonic.net/~dakidd> for more info
how to do this pls help me
how to do this pls help me
Given two integers A & B. Determine how many bits required to convert
A to B.
how to write a function int BitSwapReqd(int A, int B);
Given two integers A & B. Determine how many bits required to convert
A to B.
The number of bits required depends on the definition of conversion in
this instance. What definition are you using?
I think it's pretty clear the OP wants to find the "hamming distance"
between the base 2 expression of two integers... I'd do that like
this:
unsigned int hd(unsigned int a, unsigned int b)
{
unsigned int c=a^b, d=0;
while(c) {
d+=(c & 1);
c>>=1;
}
return d;
}
For signed integers, you'd need to worry about how the integer is
being represented - 1s/2s complement etc.
while(a) {
d+=a & 1;
a>>=1;
}
Want to reply to this thread or ask your own question?
You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.