Hacker News new | ask | show | jobs
by BoorishBears 1200 days ago
Kotlin solves this very nicely with Uxxx types, like UByte, UInt, UShort, etc.

Typing allows enforcing the boundaries where you go from signed to unsigned, and the bit fiddling is handled in the class

   UShort.toInt(): Int = data.toInt() and 0xFFFF
They're defined as inline classes/functions that have no runtime cost so it's equivalent to the "Straightforward emulation" from the article
1 comments

Another good reason to switch to Kotlin. :)