Data Types in Kotlin
As you know, a variable is a location in memory (storage area) to hold data. In this section, we are going to learn basic topic data types in kotlin: numbers, characters, booleans, arrays, and strings.
left shift, right shift, unsigned right shift, logical and, logical or and exclusive logical or – are supported by Kotlin. Unlike Java, these are not built in operators but named functions instead but can still be invoked like operators:
val leftShift =
val rightShift =
val unsignedRightShift =
val and =
val or =
val xor =
val inv =
Notice that inverse is not a binary operator, but a unary operator and so is invoked using the dot syntax on a number.
|Long||64||2^63 -1||-9,223,372,036,854,775,808 to 9,223,372,036,854,775,807||0L|
|Int||32||2^31 -1||-2,147,483,648 to2,147,483,647||0|
|Short||16||2^15 -1||-32,768 to 32,767||0|
|Byte||8||2^7 -1||-128 to 127||0|
Booleans has two values: true and false.
Character : Characters are represented by the type Char. Character literals go in single quotes:
'1'. Special characters can be escaped using a backslash. The following escape sequences are supported:
\$. To encode any other character, use the Unicode escape sequence syntax:
Strings: strings are represented by the type
val info = "hello world"
How to declare a variable in Kotlin?
next tutorial we learn about type conversion in Kotlin.