Using 2 bytes words like Uint (0 to 65535) and Int (-32768 to 32767) special care has to be taken if the low- and high byte are needed. This is e.g. in case of using EEPROM (with only bytes).
Say the 2 bytes variable is A and the low byte is A_low and the high byte is A_high.
1) To find the low- and high byte is possible like:
A_low= A & 0xx00FF //(with & is AND)
2) If the low- and high byte are known, then A can be calculated like:
A= (A-high<<8) + A_low.
I first did A= A_high<<8+A_low, but find out that gave wrong results. I had the feeling that the priority of << is higher then +. But that is wrong. The priority is shown in the table below of presence of operators.
It shows that operator + has a higher priority (4) compared to the operator << (priority=5)
In the statement A=(A_high<<8)+ A_low the parentheses () are needed. Of course, there is an alternative like:
For Flowcode users to discuss projects, flowcharts, and any other issues related to Flowcode 8.
1 post • Page 1 of 1
- Jan Lichtenbelt
- Posts: 796
- Joined: Tue Feb 17, 2009 8:35 pm
- Location: Haren GN, the Netherlands
- Has thanked: 129 times
- Been thanked: 264 times