Open main menu
Home
Random
Recent changes
Special pages
Community portal
Preferences
About Wikipedia
Disclaimers
Incubator escapee wiki
Search
User menu
Talk
Dark mode
Contributions
Create account
Log in
Editing
Integer (computer science)
(section)
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
== Syntax == {{main|Integer literal}} [[Integer literal]]s can be written as regular [[Arabic numerals]], consisting of a sequence of digits and with negation indicated by a [[hyphen-minus|minus sign]] before the value. However, most programming languages disallow use of commas or spaces for [[digit grouping]]. Examples of integer literals are: * <code>42</code> * <code>10000</code> * <code>-233000</code> <!-- do not use the real minus sign, as that isn't part of a literal --> There are several alternate methods for writing integer literals in many programming languages: * Many programming languages, especially those influenced by [[C (programming language)|C]], prefix an integer literal with <code>0X</code> or <code>0x</code> to represent a [[hexadecimal]] value, e.g. <code>0xDEADBEEF</code>. Other languages may use a different notation, e.g. some [[assembly language]]s append an <code>H</code> or <code>h</code> to the end of a hexadecimal value. * [[Perl]], [[Ruby (programming language)|Ruby]], [[Java (programming language)|Java]], [[Julia (programming language)|Julia]], [[D (programming language)|D]], [[Go (programming language)|Go]], [[C Sharp (programming language)|C#]], [[Rust (programming language)|Rust]], [[Python (programming language)|Python]] (starting from version 3.6), and [[PHP]] (from version 7.4.0 onwards<ref>https://www.php.net/manual/en/language.types.integer.php</ref>) allow embedded [[underscore]]s for clarity, e.g. <code>10_000_000</code>, and fixed-form [[Fortran]] ignores embedded spaces in integer literals. C (starting from [[C23 (C standard revision)|C23]]) and C++ use single quotes for this purpose. * In [[C (programming language)|C]] and [[C++]], a leading zero indicates an [[octal]] value, e.g. <code>0755</code>. This was primarily intended to be used with [[Modes (Unix)|Unix modes]]; however, it has been criticized because normal integers may also lead with zero.<ref>ECMAScript 6th Edition draft: https://people.mozilla.org/~jorendorff/es6-draft.html#sec-literals-numeric-literals {{webarchive|url=https://web.archive.org/web/20131216202526/https://people.mozilla.org/~jorendorff/es6-draft.html |date=2013-12-16 }}</ref> As such, [[Python (programming language)|Python]], [[Ruby (programming language)|Ruby]], [[Haskell]], and [[OCaml]] prefix octal values with <code>0O</code> or <code>0o</code>, following the layout used by hexadecimal values. * Several languages, including [[Java (programming language)|Java]], [[C Sharp (programming language)|C#]], [[Scala (programming language)|Scala]], [[Python (programming language)|Python]], [[Ruby (programming language)|Ruby]], [[OCaml]], C (starting from C23) and C++ can represent binary values by prefixing a number with <code>0B</code> or <code>0b</code>.
Edit summary
(Briefly describe your changes)
By publishing changes, you agree to the
Terms of Use
, and you irrevocably agree to release your contribution under the
CC BY-SA 4.0 License
and the
GFDL
. You agree that a hyperlink or URL is sufficient attribution under the Creative Commons license.
Cancel
Editing help
(opens in new window)