Literals/Integer: Difference between revisions

m
(→‎{{header|Kotlin}}: Updated the Kotlin example to include unsigned types)
Line 1,194:
 
=={{header|Kotlin}}==
Kotlin supports 3 types of integer literal: decimal, hexadecimal and binary. Hexadecimal literals are prefixed with <code>0x</code> or <code>0X</code>, and binary literals with <code>0b</code> or <code>0B</code>. Hexadecimal digits can be uppercase or lowercase, or a combination of the two.
 
A signed integer literal can be assigned to a variable of any signed integer type. If no type is specified, Int (4 bytes) is assumed. If the value cannot fit into an Int, Long (8 bytes) is assumed.
 
An unsigned integer literal is made by appending '<code>u'</code> or '<code>U'</code> to a signed integer literal. Unsigned literals can be assigned to any unsigned integer type, with UInt (4 bytes) being assumed if none is specified, or ULong (8 bytes) if the value cannot fit into a UInt.
 
Signed and unsigned integer literals can be forced to be interpreted as Long or ULong respectively by appending the suffix '<code>L'</code> to the literal (lower case 'l' is not allowed as it is easily confused with the digit '1').
 
<syntaxhighlight lang="kotlin">
32

edits