Unpacking packed int

I came up with these methods to pack and unpack ints:
public static int packInts(int first4, int last4) {
return (first4 << 16) | last4;
}
public static Vector2i unpackInt(int all8) {
return new Vector2i(all8 << 16, all8 >> 16);
}
public static int packInts(int first4, int last4) {
return (first4 << 16) | last4;
}
public static Vector2i unpackInt(int all8) {
return new Vector2i(all8 << 16, all8 >> 16);
}
However when I unpack the packed int I get an unepxected result. For example if I pack (3, 2) then unpack it I get (131072, 3)
8 Replies
JavaBot
JavaBotā€¢3mo ago
āŒ› This post has been reserved for your question.
Hey @š“pothicon! Please use /close or the Close Post button above when your problem is solved. Please remember to follow the help guidelines. This post will be automatically marked as dormant after 300 minutes of inactivity.
TIP: Narrow down your issue to simple and precise questions to maximize the chance that others will reply in here.
dan1st
dan1stā€¢3mo ago
that's because the unpack method doesn't... unpack that if you want to revert the << 16, you'd need >> 16
š“pothicon
š“pothiconOPā€¢3mo ago
i do have a >> 16
dan1st
dan1stā€¢3mo ago
and to revert the |/get the second part back, you'd need & 0xFFFF
š“pothicon
š“pothiconOPā€¢3mo ago
wait i got it
No description
š“pothicon
š“pothiconOPā€¢3mo ago
thanks
JavaBot
JavaBotā€¢3mo ago
If you are finished with your post, please close it. If you are not, please ignore this message. Note that you will not be able to send further messages here after this post have been closed but you will be able to create new posts.
JavaBot
JavaBotā€¢3mo ago
Post Closed
This post has been closed by <@465515365108154380>.

Did you find this page helpful?