0

Hi guys! Well I'll be quick, I just want to know how the formula below works.

Ls = least significant bit;
Ms = most significant bit;


Ls | Ls1 << 8 | Ls2 << 16 | Ms << 24

This formula is intended to turn four separate bytes into a single 32 bit number in java.
Can you give me any example about how it works?


Thanks!

2
Contributors
1
Reply
2
Views
6 Years
Discussion Span
Last Post by bibiki
0

this is a Java forum man, I don't know how is this related to java, but anyways:

say you have a binary number as follows 1001. that is, you have four digits. what 1001 actually says is that you have 1*2^3 + 0*2^2 + 0*2^1 + 1 *2^0 = 8 + 0 + 0 + 1 = 9. Analogously. you can find a 32 digit binary number's decimal equivalent.

AND, your most significant bit is the left-most bit as it indicates the highest power of two; your least significant bit is the right-most bit... say you have a decimal number 999. if you reduce the first digit by one, you reduced the number 999 by 100. if you reduce the last digit by 1, you reduce the number 999 by 1. this is why most significant bit is the left most one, and the least significant bit the right most one.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.