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!

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.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.