Numeric Types

Kotlin supports several numeric types. Regardless of which platform you target, the rules for these numeric types stay the same. As of Kotlin 1.5, numeric types in Kotlin come in two flavors: signed and unsigned. Signed numbers can represent both positive and negative numbers. Unsigned numbers can only represent positive numbers. We will discuss signed numbers first and come back to their unsigned counterparts in the section called For the More Curious: Unsigned Numbers near the end of this chapter.

In addition to whether a number has a sign, there are several key differences between Kotlin’s numeric types. Numeric types primarily differ in the number of bits they are allocated in memory and, consequently, their minimum ...

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.