How to find the number of msb bits common between two binary numbers

Clash Royale CLAN TAG#URR8PPP
up vote
0
down vote
favorite
Im trying to find the number of bits common between two binary numbers starting from MSB -> LSB. For example, I'm taking a set of binary numbers of 4 bits each i.e., 0 -> 15.
- I'm trying to find the number of common bits between 8(1000) and
12(1100). Starting from msb we see that there is only one common bit.
hence answer should be (1) - 0(0000) and 15(1111) = 0
- 10(1010) and 11(1011) = 3
- 6(0110) and 8(1000) = 0
Is there a formula to do this? Or should it be brute forced by checking each bit when writing code?
binary-operations binary-programming
 |Â
show 1 more comment
up vote
0
down vote
favorite
Im trying to find the number of bits common between two binary numbers starting from MSB -> LSB. For example, I'm taking a set of binary numbers of 4 bits each i.e., 0 -> 15.
- I'm trying to find the number of common bits between 8(1000) and
12(1100). Starting from msb we see that there is only one common bit.
hence answer should be (1) - 0(0000) and 15(1111) = 0
- 10(1010) and 11(1011) = 3
- 6(0110) and 8(1000) = 0
Is there a formula to do this? Or should it be brute forced by checking each bit when writing code?
binary-operations binary-programming
What are msb and lsb? And if you're using a computer, look for "bitwise xor". It will get you part of the way.
â Arthur
Sep 4 at 6:04
1
(Bitwise xnor is actually more correct, sorry about that. I would think you find information on both in more or less the same place.)
â Arthur
Sep 4 at 6:11
@Arthur I believe it is "most significant bit" and "least significant bit".
â GoodDeeds
Sep 4 at 6:11
@postmortes MSB is the left most digit and LSB is the right most digit
â Bhargav
Sep 4 at 6:32
@Arthur Thanks for pointing this out. But do I still have to look for every bit which is '1' after doing xnor. Taking 10(1010) and 11(1011). XNOR(1010,1011) gives 1110.
â Bhargav
Sep 4 at 6:36
 |Â
show 1 more comment
up vote
0
down vote
favorite
up vote
0
down vote
favorite
Im trying to find the number of bits common between two binary numbers starting from MSB -> LSB. For example, I'm taking a set of binary numbers of 4 bits each i.e., 0 -> 15.
- I'm trying to find the number of common bits between 8(1000) and
12(1100). Starting from msb we see that there is only one common bit.
hence answer should be (1) - 0(0000) and 15(1111) = 0
- 10(1010) and 11(1011) = 3
- 6(0110) and 8(1000) = 0
Is there a formula to do this? Or should it be brute forced by checking each bit when writing code?
binary-operations binary-programming
Im trying to find the number of bits common between two binary numbers starting from MSB -> LSB. For example, I'm taking a set of binary numbers of 4 bits each i.e., 0 -> 15.
- I'm trying to find the number of common bits between 8(1000) and
12(1100). Starting from msb we see that there is only one common bit.
hence answer should be (1) - 0(0000) and 15(1111) = 0
- 10(1010) and 11(1011) = 3
- 6(0110) and 8(1000) = 0
Is there a formula to do this? Or should it be brute forced by checking each bit when writing code?
binary-operations binary-programming
binary-operations binary-programming
asked Sep 4 at 5:59
Bhargav
11
11
What are msb and lsb? And if you're using a computer, look for "bitwise xor". It will get you part of the way.
â Arthur
Sep 4 at 6:04
1
(Bitwise xnor is actually more correct, sorry about that. I would think you find information on both in more or less the same place.)
â Arthur
Sep 4 at 6:11
@Arthur I believe it is "most significant bit" and "least significant bit".
â GoodDeeds
Sep 4 at 6:11
@postmortes MSB is the left most digit and LSB is the right most digit
â Bhargav
Sep 4 at 6:32
@Arthur Thanks for pointing this out. But do I still have to look for every bit which is '1' after doing xnor. Taking 10(1010) and 11(1011). XNOR(1010,1011) gives 1110.
â Bhargav
Sep 4 at 6:36
 |Â
show 1 more comment
What are msb and lsb? And if you're using a computer, look for "bitwise xor". It will get you part of the way.
â Arthur
Sep 4 at 6:04
1
(Bitwise xnor is actually more correct, sorry about that. I would think you find information on both in more or less the same place.)
â Arthur
Sep 4 at 6:11
@Arthur I believe it is "most significant bit" and "least significant bit".
â GoodDeeds
Sep 4 at 6:11
@postmortes MSB is the left most digit and LSB is the right most digit
â Bhargav
Sep 4 at 6:32
@Arthur Thanks for pointing this out. But do I still have to look for every bit which is '1' after doing xnor. Taking 10(1010) and 11(1011). XNOR(1010,1011) gives 1110.
â Bhargav
Sep 4 at 6:36
What are msb and lsb? And if you're using a computer, look for "bitwise xor". It will get you part of the way.
â Arthur
Sep 4 at 6:04
What are msb and lsb? And if you're using a computer, look for "bitwise xor". It will get you part of the way.
â Arthur
Sep 4 at 6:04
1
1
(Bitwise xnor is actually more correct, sorry about that. I would think you find information on both in more or less the same place.)
â Arthur
Sep 4 at 6:11
(Bitwise xnor is actually more correct, sorry about that. I would think you find information on both in more or less the same place.)
â Arthur
Sep 4 at 6:11
@Arthur I believe it is "most significant bit" and "least significant bit".
â GoodDeeds
Sep 4 at 6:11
@Arthur I believe it is "most significant bit" and "least significant bit".
â GoodDeeds
Sep 4 at 6:11
@postmortes MSB is the left most digit and LSB is the right most digit
â Bhargav
Sep 4 at 6:32
@postmortes MSB is the left most digit and LSB is the right most digit
â Bhargav
Sep 4 at 6:32
@Arthur Thanks for pointing this out. But do I still have to look for every bit which is '1' after doing xnor. Taking 10(1010) and 11(1011). XNOR(1010,1011) gives 1110.
â Bhargav
Sep 4 at 6:36
@Arthur Thanks for pointing this out. But do I still have to look for every bit which is '1' after doing xnor. Taking 10(1010) and 11(1011). XNOR(1010,1011) gives 1110.
â Bhargav
Sep 4 at 6:36
 |Â
show 1 more comment
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmath.stackexchange.com%2fquestions%2f2904680%2fhow-to-find-the-number-of-msb-bits-common-between-two-binary-numbers%23new-answer', 'question_page');
);
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
What are msb and lsb? And if you're using a computer, look for "bitwise xor". It will get you part of the way.
â Arthur
Sep 4 at 6:04
1
(Bitwise xnor is actually more correct, sorry about that. I would think you find information on both in more or less the same place.)
â Arthur
Sep 4 at 6:11
@Arthur I believe it is "most significant bit" and "least significant bit".
â GoodDeeds
Sep 4 at 6:11
@postmortes MSB is the left most digit and LSB is the right most digit
â Bhargav
Sep 4 at 6:32
@Arthur Thanks for pointing this out. But do I still have to look for every bit which is '1' after doing xnor. Taking 10(1010) and 11(1011). XNOR(1010,1011) gives 1110.
â Bhargav
Sep 4 at 6:36