Literals/Integer: Difference between revisions

Content added Content deleted
(Added Kotlin)
Line 753:
<lang julia>julia> 0b1011010111 == 0o1327 == 0x2d7 == 727
true</lang>
 
=={{header|Kotlin}}==
Kotlin supports 3 types of integer literal (signed 4 byte), namely : decimal, hexadecimal and binary.
 
These can be converted to long integer literals (signed 8 byte) by appending the suffix 'L' (lower case 'l' is not allowed as it is easily confused with the digit '1').
 
It is also possible to assign integer literals to variables of type Short (signed 2 byte) or Byte (signed 1 byte). They will be automatically converted by the compiler provided they are within the range of the variable concerned.
<lang scala>// version 1.0.6
 
fun main(args: Array<String>) {
val d = 255 // decimal integer literal
val h = 0xff // hexadecimal integer literal
val b = 0b11111111 // binary integer literal
 
val ld = 255L // decimal long integer literal (can't use l instead of L)
val lh = 0xffL // hexadecimal long integer literal (could use 0X rather than 0x)
val lb = 0b11111111L // binary long integer literal (could use 0B rather than 0b)
 
val sd : Short = 127 // decimal integer literal automatically converted to Short
val sh : Short = 0x7f // hexadecimal integer literal automatically converted to Short
val bd : Byte = 0b01111111 // binary integer literal automatically converted to Byte
 
println("$d $h $b $ld $lh $lb $sd $sh $bd")
}</lang>
 
{{out}}
<pre>
255 255 255 255 255 255 127 127 127
</pre>
 
=={{header|Lasso}}==