Int

Platform and version requirements: JVM (1.0), JS (1.0), Native (1.3)
class Int : Number, Comparable<Int>
For Common, JVM, JS

Represents a 32-bit signed integer. On the JVM, non-nullable values of this type are represented as values of the primitive type int.

For Native

Represents a 32-bit signed integer.

Functions

Platform and version requirements: JVM (1.0), JS (1.0), Native (1.0)

and

Performs a bitwise AND operation between the two values.

infix fun and(other: Int): Int
Platform and version requirements: JVM (1.0), JS (1.0), Native (1.0)

compareTo

Compares this value with the specified value for order. Returns zero if this value is equal to the specified other value, a negative number if it's less than other, or a positive number if it's greater than other.

operator fun compareTo(other: Byte): Int
operator fun compareTo(other: Short): Int
operator fun compareTo(other: Int): Int
operator fun compareTo(other: Long): Int
operator fun compareTo(other: Float): Int
operator fun compareTo(other: Double): Int
Platform and version requirements: JVM (1.0), JS (1.0), Native (1.0)

dec

Returns this value decremented by one.

operator fun dec(): Int
Platform and version requirements: JVM (1.0), JS (1.0), Native (1.0)

div

Divides this value by the other value, truncating the result to an integer that is closer to zero.

operator fun div(other: Byte): Int
operator fun div(other: Short): Int
operator fun div(other: Int): Int
operator fun div(other: Long): Long

Divides this value by the other value.

operator fun div(other: Float): Float
operator fun div(other: Double): Double
Platform and version requirements: Native (1.3)

equals

fun equals(other: Int): Boolean

Indicates whether some other object is "equal to" this one. Implementations must fulfil the following requirements:

fun equals(other: Any?): Boolean
Platform and version requirements: Native (1.3)

hashCode

Returns a hash code value for the object. The general contract of hashCode is:

fun hashCode(): Int
Platform and version requirements: JVM (1.0), JS (1.0), Native (1.0)

inc

Returns this value incremented by one.

operator fun inc(): Int
Platform and version requirements: JVM (1.0), JS (1.0), Native (1.0)

inv

Inverts the bits in this value.

fun inv(): Int
Platform and version requirements: JVM (1.0), JS (1.0), Native (1.0)

minus

Subtracts the other value from this value.

operator fun minus(other: Byte): Int
operator fun minus(other: Short): Int
operator fun minus(other: Int): Int
operator fun minus(other: Long): Long
operator fun minus(other: Float): Float
operator fun minus(other: Double): Double
Platform and version requirements: JVM (1.0), JS (1.0), Native (1.0)

or

Performs a bitwise OR operation between the two values.

infix fun or(other: Int): Int
Platform and version requirements: JVM (1.0), JS (1.0), Native (1.0)

plus

Adds the other value to this value.

operator fun plus(other: Byte): Int
operator fun plus(other: Short): Int
operator fun plus(other: Int): Int
operator fun plus(other: Long): Long
operator fun plus(other: Float): Float
operator fun plus(other: Double): Double
Platform and version requirements: JVM (1.0), JS (1.0), Native (1.0)

rangeTo

Creates a range from this value to the specified other value.

operator fun rangeTo(other: Byte): IntRange
operator fun rangeTo(other: Short): IntRange
operator fun rangeTo(other: Int): IntRange
operator fun rangeTo(other: Long): LongRange
Platform and version requirements: JVM (1.1), JS (1.1), Native (1.1)

rem

Calculates the remainder of truncating division of this value by the other value.

operator fun rem(other: Byte): Int
operator fun rem(other: Short): Int
operator fun rem(other: Int): Int
operator fun rem(other: Long): Long
operator fun rem(other: Float): Float
operator fun rem(other: Double): Double
Platform and version requirements: JVM (1.0), JS (1.0), Native (1.0)

shl

Shifts this value left by the bitCount number of bits.

infix fun shl(bitCount: Int): Int
Platform and version requirements: JVM (1.0), JS (1.0), Native (1.0)

shr

Shifts this value right by the bitCount number of bits, filling the leftmost bits with copies of the sign bit.

infix fun shr(bitCount: Int): Int
Platform and version requirements: JVM (1.0), JS (1.0), Native (1.0)

times

Multiplies this value by the other value.

operator fun times(other: Byte): Int
operator fun times(other: Short): Int
operator fun times(other: Int): Int
operator fun times(other: Long): Long
operator fun times(other: Float): Float
operator fun times(other: Double): Double
Platform and version requirements: JVM (1.0), JS (1.0), Native (1.0)

toByte

Converts this Int value to Byte.

fun toByte(): Byte
Platform and version requirements: JVM (1.0), JS (1.0), Native (1.0)

toChar

Converts this Int value to Char.

fun toChar(): Char
Platform and version requirements: JVM (1.0), JS (1.0), Native (1.0)

toDouble

Converts this Int value to Double.

fun toDouble(): Double
Platform and version requirements: JVM (1.0), JS (1.0), Native (1.0)

toFloat

Converts this Int value to Float.

fun toFloat(): Float
Platform and version requirements: JVM (1.0), JS (1.0), Native (1.0)

toInt

Returns this value.

fun toInt(): Int
Platform and version requirements: JVM (1.0), JS (1.0), Native (1.0)

toLong

Converts this Int value to Long.

fun toLong(): Long
Platform and version requirements: JVM (1.0), JS (1.0), Native (1.0)

toShort

Converts this Int value to Short.

fun toShort(): Short
Platform and version requirements: Native (1.3)

toString

Returns a string representation of the object.

fun toString(): String
Platform and version requirements: JVM (1.0), JS (1.0), Native (1.0)

unaryMinus

Returns the negative of this value.

operator fun unaryMinus(): Int
Platform and version requirements: JVM (1.0), JS (1.0), Native (1.0)

unaryPlus

Returns this value.

operator fun unaryPlus(): Int
Platform and version requirements: JVM (1.0), JS (1.0), Native (1.0)

ushr

Shifts this value right by the bitCount number of bits, filling the leftmost bits with zeros.

infix fun ushr(bitCount: Int): Int
Platform and version requirements: JVM (1.0), JS (1.0), Native (1.0)

xor

Performs a bitwise XOR operation between the two values.

infix fun xor(other: Int): Int

Companion Object Properties

Platform and version requirements: JVM (1.0), JS (1.0), Native (1.0)

MAX_VALUE

A constant holding the maximum value an instance of Int can have.

const val MAX_VALUE: Int
Platform and version requirements: JVM (1.0), JS (1.0), Native (1.0)

MIN_VALUE

A constant holding the minimum value an instance of Int can have.

const val MIN_VALUE: Int
Platform and version requirements: JVM (1.3), JS (1.3), Native (1.3)

SIZE_BITS

The number of bits used to represent an instance of Int in a binary form.

const val SIZE_BITS: Int
Platform and version requirements: JVM (1.3), JS (1.3), Native (1.3)

SIZE_BYTES

The number of bytes used to represent an instance of Int in a binary form.

const val SIZE_BYTES: Int

Extension Properties

Platform and version requirements: JVM (1.3), JS (1.3), Native (1.3)

days

Returns a Duration equal to this Int number of days.

val Int.days: Duration
Platform and version requirements: JVM (1.3), JS (1.3), Native (1.3)

hours

Returns a Duration equal to this Int number of hours.

val Int.hours: Duration
Platform and version requirements: JVM (1.3), JS (1.3), Native (1.3)

microseconds

Returns a Duration equal to this Int number of microseconds.

val Int.microseconds: Duration
Platform and version requirements: JVM (1.3), JS (1.3), Native (1.3)

milliseconds

Returns a Duration equal to this Int number of milliseconds.

val Int.milliseconds: Duration
Platform and version requirements: JVM (1.3), JS (1.3), Native (1.3)

minutes

Returns a Duration equal to this Int number of minutes.

val Int.minutes: Duration
Platform and version requirements: JVM (1.3), JS (1.3), Native (1.3)

nanoseconds

Returns a Duration equal to this Int number of nanoseconds.

val Int.nanoseconds: Duration
Platform and version requirements: JVM (1.3), JS (1.3), Native (1.3)

seconds

Returns a Duration equal to this Int number of seconds.

val Int.seconds: Duration

Extension Functions

Platform and version requirements: JVM (1.0), JS (1.0), Native (1.0)

coerceAtLeast

Ensures that this value is not less than the specified minimumValue.

fun Int.coerceAtLeast(minimumValue: Int): Int
fun <T : Comparable<T>> T.coerceAtLeast(minimumValue: T): T
Platform and version requirements: JVM (1.0), JS (1.0), Native (1.0)

coerceAtMost

Ensures that this value is not greater than the specified maximumValue.

fun Int.coerceAtMost(maximumValue: Int): Int
fun <T : Comparable<T>> T.coerceAtMost(maximumValue: T): T
Platform and version requirements: JVM (1.0), JS (1.0), Native (1.0)

coerceIn

Ensures that this value lies in the specified range minimumValue..maximumValue.

fun Int.coerceIn(minimumValue: Int, maximumValue: Int): Int
fun <T : Comparable<T>> T.coerceIn(
    minimumValue: T?, 
    maximumValue: T?
): T

Ensures that this value lies in the specified range.

fun Int.coerceIn(range: ClosedRange<Int>): Int
fun <T : Comparable<T>> T.coerceIn(
    range: ClosedFloatingPointRange<T>
): T
fun <T : Comparable<T>> T.coerceIn(range: ClosedRange<T>): T
Platform and version requirements: JVM (1.6), JS (1.6), Native (1.6)

compareTo

Compares this object with the specified object for order. Returns zero if this object is equal to the specified other object, a negative number if it's less than other, or a positive number if it's greater than other.

infix fun <T> Comparable<T>.compareTo(other: T): Int
Platform and version requirements: Native (1.3)

convert

fun <R : Any> Int.convert(): R
Platform and version requirements: JVM (1.5), JS (1.5), Native (1.5)

digitToChar

Returns the Char that represents this decimal digit. Throws an exception if this value is not in the range 0..9.

fun Int.digitToChar(): Char

Returns the Char that represents this numeric digit value in the specified radix. Throws an exception if the radix is not in the range 2..36 or if this value is not in the range 0 until radix.

fun Int.digitToChar(radix: Int): Char
Platform and version requirements: JVM (1.0), JS (1.0), Native (1.0)

downTo

Returns a progression from this value down to the specified to value with the step -1.

infix fun Int.downTo(to: Byte): IntProgression
infix fun Int.downTo(to: Int): IntProgression
infix fun Int.downTo(to: Long): LongProgression
infix fun Int.downTo(to: Short): IntProgression
Platform and version requirements: JVM (1.5), JS (1.5), Native (1.5)

floorDiv

Divides this value by the other value, flooring the result to an integer that is closer to negative infinity.

fun Int.floorDiv(other: Byte): Int
fun Int.floorDiv(other: Short): Int
fun Int.floorDiv(other: Int): Int
fun Int.floorDiv(other: Long): Long
Platform and version requirements: JVM (1.5), JS (1.5), Native (1.5)

mod

Calculates the remainder of flooring division of this value by the other value.

fun Int.mod(other: Byte): Byte
fun Int.mod(other: Short): Short
fun Int.mod(other: Int): Int
fun Int.mod(other: Long): Long
Platform and version requirements: Native (1.3)

narrow

fun <R : Number> Number.narrow(): R
Platform and version requirements: JVM (1.0), JS (1.0), Native (1.0)

rangeTo

Creates a range from this Comparable value to the specified that value.

operator fun <T : Comparable<T>> T.rangeTo(
    that: T
): ClosedRange<T>
Platform and version requirements: Native (1.3)

signExtend

fun <R : Number> Number.signExtend(): R
Platform and version requirements: JVM (1.6), JS (1.6), Native (1.6)

times

Returns a duration whose value is the specified duration value multiplied by this number.

operator fun Int.times(duration: Duration): Duration
Platform and version requirements: JVM (1.2)

toBigDecimal

Returns the value of this Int number as a BigDecimal.

fun Int.toBigDecimal(): BigDecimal
fun Int.toBigDecimal(mathContext: MathContext): BigDecimal
Platform and version requirements: JVM (1.2)

toBigInteger

Returns the value of this Int number as a BigInteger.

fun Int.toBigInteger(): BigInteger
Platform and version requirements: JVM (1.6), JS (1.6), Native (1.6)

toDuration

Returns a Duration equal to this Int number of the specified unit.

fun Int.toDuration(unit: DurationUnit): Duration
Platform and version requirements: JVM (1.5), JS (1.5), Native (1.5)

toUByte

Converts this Int value to UByte.

fun Int.toUByte(): UByte
Platform and version requirements: JVM (1.5), JS (1.5), Native (1.5)

toUInt

Converts this Int value to UInt.

fun Int.toUInt(): UInt
Platform and version requirements: JVM (1.5), JS (1.5), Native (1.5)

toULong

Converts this Int value to ULong.

fun Int.toULong(): ULong
Platform and version requirements: JVM (1.5), JS (1.5), Native (1.5)

toUShort

Converts this Int value to UShort.

fun Int.toUShort(): UShort
Platform and version requirements: JVM (1.0), JS (1.0), Native (1.0)

until

Returns a range from this value up to but excluding the specified to value.

infix fun Int.until(to: Byte): IntRange
infix fun Int.until(to: Int): IntRange
infix fun Int.until(to: Long): LongRange
infix fun Int.until(to: Short): IntRange

© 2010–2021 JetBrains s.r.o. and Kotlin Programming Language contributors
Licensed under the Apache License, Version 2.0.
https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-int/index.html