Skip to content

An 8 bit mask may be needed #21

@scuniff

Description

@scuniff

An 8 bit mask may be needed

https://github.com/fiji/IO/blob/1fa709937a44b369c3d56545cea191f0b0b821ed/src/main/java/sc/fiji/io/icns/IOSupport.java

Line 104:
return ((data[0] & 0xFF) << 8) + data[1];

should have an 8 bit mask & operation added:
return ((data[0] & 0xFF) << 8) + (data[1] & 0xff);

This eliminates sign extension issue.

This snippet I think exemplifies the fix:

    byte[] data = new byte[2];
    data[0] = (byte)0x80;
    data[1] = (byte)0x80;

    long incorrect = ((data[0] & 0xff) << 8)  + (data[1]);
	System.out.println("Incorrect " + String.format("0x%08X", incorrect));

	long correct = ((data[0] & 0xff) << 8)  + (data[1] & 0xff);
	System.out.println("correct " + String.format("0x%08X", correct));

Output:

Incorrect 0x00007F80
correct 0x00008080

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions