For the More Curious: Unsigned Numbers

Kotlin 1.5 introduced unsigned numeric types as a stable language feature. They are very similar to the numeric types you have seen so far, except that they cannot express negative values. Table 5.2 shows the unsigned numeric types available in Kotlin.

Table 5.2  Unsigned numeric types in Kotlin

Type Bits Max Value Min Value
UByte 8 255 0
UShort 16 65,535 0
UInt 32 4,294,967,295 0
ULong 64 18,446,744,073,709,551,615 0

There are similarities and differences between these unsigned numeric types and the signed numeric types introduced earlier in this chapter. For one thing, the floating-point numeric types – Float and Double – have no unsigned counterparts. We ...

Get Kotlin Programming: The Big Nerd Ranch Guide, 2nd Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.