Skip to main content
gamedev.net
🔒 Locked

parsing java classfiles - reading a 4 byte unsigned integer

Started by fosh 3 replies 1.3k views
Original Post
fosh
fosh
Hey guys. Im currently writing something to calculate some metrics given a classfile, and am having trouble reading the 4-byte unsigned attribute_count field in one of the structures. How exactly can you go about doing this? The lack of unsigned types in java makes it a bit fiddly. ive been trying int Data1 = Data.readUnsignedInt() ; int Data2 = Data.readUnsignedInt() ; long Final = (Data1 << 16) || (Data2) ; I think this doesn't work because of the high-order bit being interpreted as the sign bit tho. Im not really sure how java stores integer values (2's complement?!) so i dont know where to go from here. any help would be appreciated Scott
fosh
fosh
You would be able to if it was a normal length signed integer but its not.
omgomghilol
omgomghilol
I'm fairly sure ints are 4 bytes in Java. And yes, they are stored 2's complement.
Zahlman
Zahlman
Java int is guaranteed by standard to be exactly 4 bytes of 8 bits each, representing a signed value by 2s complement. I really don't understand how you can know anything about the classfile structure and thus refer to a field labelled "attribute_count", but not know this and be able to figure out how to work with it. Hint: try the *other* chapters in the JLS.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.