Literals/Integer: Difference between revisions

m
→‎{{header|Wren}}: Changed to Wren S/H
(→‎{{header|Kotlin}}: Updated the Kotlin example to include unsigned types)
m (→‎{{header|Wren}}: Changed to Wren S/H)
 
(11 intermediate revisions by 7 users not shown)
Line 623:
return 0;
}</syntaxhighlight>
 
=={{header|Cherrycake}}==
 
<syntaxhighlight lang="cherrycake">
515142 # Interpretted as an integer, 515142
0b10111011 # Interpretted as a binary integer, 10111011 (187)
0x0AB3 # Interpretted as a binary integer, 0AB3 (2739)
</syntaxhighlight>
 
=={{header|Clojure}}==
Line 835 ⟶ 843:
 
The digits and the radix character can both be any mixture of upper and lower case. See [http://www.gnu.org/software/emacs/manual/html_node/elisp/Integer-Basics.html GNU Elisp reference manual "Integer Basics"].
 
=={{header|EMal}}==
<syntaxhighlight lang="emal">
^|
| EMal internally uses 64 bit signed integers.
|^
int hex = 0xff # base16
int oct = 0o377 # base8
int bin = 0b11111111 # base2
int dec = 255 # base10
writeLine(hex)
writeLine(oct)
writeLine(bin)
writeLine(dec)
# here we check that they give the same value
writeLine(0b1011010111 == 0o1327 and
0o1327 == 0x2d7 and
0x2d7 == 727 and
727 == 0b1011010111)
</syntaxhighlight>
{{out}}
<pre>
255
255
255
255
</pre>
 
=={{header|Erlang}}==
Line 1,123 ⟶ 1,159:
every write(!L)
end</syntaxhighlight>
 
=={{Header|Insitux}}==
 
<syntaxhighlight lang="insitux">
[123 0x7F 0xFFF 0b0101001]
</syntaxhighlight>
 
{{out}}
 
<pre>
[123 127 4095 41]
</pre>
 
=={{header|J}}==
Line 1,194 ⟶ 1,242:
 
=={{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').
 
Underscores can be used between digits of a literal for clarity.
Signed and unsigned integer literals can be forced to be interpreted as Long or ULong respectively by appending the suffix 'L' to the literal (lower case 'l' is not allowed as it is easily confused with the digit '1').
 
<syntaxhighlight lang="kotlin">
Line 2,013 ⟶ 2,063:
</pre>
 
Unsigned integers, which must begin with <code>#</code>, can be expressed in binary, octal, decimal or hexadecimal. A final lowercase letter defines the base.
#100111010b
#472o
#314d
#13Ah
 
=={{header|RPL}}==
#1011b <span style="color:grey">@ Base 2</span>
#1234o <span style="color:grey">@ Base 8</span>
#6789d <span style="color:grey">@ Base 10</span>
#ABCDh <span style="color:grey">@ Base 16</span>
=={{header|Ruby}}==
 
Line 2,227 ⟶ 2,288:
<syntaxhighlight lang="usala">t = 4534934521_</syntaxhighlight>
is used for numbers stored in binary converted decimal format, also with unlimited precision, which may perform better in applications involving very large decimal numbers.
 
=={{header|Uxntal}}==
Uxntal only allows hexadecimal literals, and they can be either one or two bytes. In order to push them to the stack, rather than writing them directly to the assembled binary, they must be prefixed with <code>#</code>.
<syntaxhighlight lang="Uxntal">#2a ( byte literal )
#c0de ( short literal )</syntaxhighlight>
And yes, they do have to be in lowercase hex.
 
=={{header|Verbexx}}==
Line 2,303 ⟶ 2,370:
End Sub</syntaxhighlight>
 
=={{header|V (Vlang)}}==
<syntaxhighlight lang="Vlang">
fn main() {
w := 727
x := 0x2d7
y := 0o1327
z := 0b10110_10111
println([w, x, y, z])
}
</syntaxhighlight>
 
{{out}}
<pre>
[727, 727, 727, 727]
</pre>
 
=={{header|Wren}}==
Line 2,312 ⟶ 2,395:
 
As the only difference between integers and other numbers is that the former do not have a decimal part, it is also possible to represent integers using scientific notation.
<syntaxhighlight lang="ecmascriptwren">var a = 255
var b = 0xff
var c = 0255 // not an octal literal
9,485

edits