kapilojha / zephyropen

Automatically exported from code.google.com/p/zephyropen
0 stars 0 forks source link

ZephyrUtils.mergeUnsigned(int, int) is not working #2

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1. Reading a HXM device serialport and combining two unsigned bytes with
zephyr.device.ZephyrUtils.mergeUnsigned(int, int)
2. As a result most of the integer values read from the device are incorrect.

What is the expected output? What do you see instead?
The bytes are not combined correctly and the integer result will be between
-32,768 to +32,767 when the correct result should be between 0-65 535

The bytes are not combined correctly. In fact the mergeUnsigned method is a
copy of mergeSigned method of the same ZephyrUtils.jave source file

To fix this issue use the following code that actually combines two bytes
as unsigned integer

    /**
     * Merge two bytes into a unsigned integer
     * 
     * @param low
     *            byte is LSB
     * @param high
     *            byte is the MSB
     * @return an unsigned int value
     */
    public static int mergeUnsigned(byte low, byte high) {
        int lint = low & 0xff;
        int hint = high & 0xff;
        return (int)( hint << 8 | lint );

    }

What version of the product are you using? On what operating system?
Framework 1.1.7, Linux Ubuntu 9.04

Original issue reported on code.google.com by olli.erj...@gmail.com on 4 Sep 2009 at 10:57

GoogleCodeExporter commented 9 years ago
This method will be committed to SVN this week. 

Original comment by brad.zdanivsky on 14 Sep 2009 at 8:03