I have a little issue trying to combine 4 digits together to give me the correct decimal value. First let me start with my code.
long firsttwo, secondtwo, combined;
firsttwo = 0x0C;
secondtwo = 0x6C;
The Decimal value of 0C : 12
The Decimal value of 6C : 108
But the Decimal value of all 0C6C : 3180
Now how do I get all the digits into one variable to be able to convert it to decimal correctely? Because if I just convert firsttwo
by itself then secondtwo
by itself I don't get the same final total. Thanks!
You need to shift the most significant byte when combining:
combined = (firsttwo << 8) | secondtwo;
this sets combined
to 0x0c6c.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.