Literals/Integer: Difference between revisions

no edit summary
No edit summary
Line 5:
Note: this should '''not''' involve the calling of any functions/methods but should be interpreted by the compiler or interpreter as an integer written to a given base.
 
Also show any other ways of expressing literals, e.g. for different types of integers.
 
=={{header|Ada}}==
Line 159 ⟶ 160:
Java has no way of specifying integers in binary.
 
You may also specify a <tt>long</tt> literal by adding an <tt>l</tt> or <tt>L</tt> (the latter form is preferred as the former looks like a "1") to the end (ex: <tt>long a = 727L574298540721727L</tt>), thoughand this is not required becausefor <tt>int</tt>snumbers coercethat intoare too large to be expressed as an <tt>longint</tt>s.
 
=={{header|JavaScript}}==
Line 180 ⟶ 181:
- : bool = true
# 727 = 0x2d7;;
- : bool = true
# 12345 = 12_345 (* underscores are ignored; useful for keeping track of places *);;
- : bool = true
</lang>
 
Literals for the other built-in integer types:
* <tt>727l</tt> - int32
* <tt>727L</tt> - int64
* <tt>727n</tt> - nativeint
 
=={{header|Perl}}==
Line 188 ⟶ 196:
print "true\n" if ( 727 == 0x2d7 &&
727 == 01327 &&
727 == 0b1011010111 );&&
12345 == 12_345 # underscores are ignored; useful for keeping track of places
);
</lang>
 
Line 220 ⟶ 230:
>>>
</lang>
 
In Python 2.x you may also specify a <tt>long</tt> literal by adding an <tt>l</tt> or <tt>L</tt> (the latter form is preferred as the former looks like a "1") to the end (ex: <tt>574298540721727L</tt>), but this is optional, as integer literals that are too large for an <tt>int</tt> will be interpreted as a <tt>long</tt>.
 
=={{header|Ruby}}==
 
(This is an interactive rubyirb session)
 
<pre>
Line 231 ⟶ 243:
=> true
irb(main):003:0> 727 == 01327
=> true
irb(main):001:0> 12345 == 12_345 # underscores are ignored; useful for keeping track of places
=> true
</pre>
Anonymous user