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
Hexadecimal
(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!
====Distinguishing from decimal==== In contexts where the [[radix|base]] is not clear, hexadecimal numbers can be ambiguous and confused with numbers expressed in other bases. There are several conventions for expressing values unambiguously. A numerical subscript (itself written in decimal) can give the base explicitly: 159<sub>10</sub> is decimal 159; 159<sub>16</sub> is hexadecimal 159, which equals 345<sub>10</sub>. Some authors prefer a text subscript, such as 159<sub>decimal</sub> and 159<sub>hex</sub>, or 159<sub>d</sub> and 159<sub>h</sub>. [[Donald Knuth]] introduced the use of a particular typeface to represent a particular radix in his book ''The TeXbook''.<ref>{{Cite book |last=Knuth |first=Donald Ervin |url=https://www.worldcat.org/oclc/12973034 |title=The TeXbook |date=1986 |others=Duane Bibby |isbn=0-201-13447-0 |location=Reading, Mass. |oclc=12973034 |access-date=2022-03-15 |archive-date=2022-01-16 |archive-url=https://web.archive.org/web/20220116012119/http://www.worldcat.org/oclc/12973034 |url-status=live }}</ref> Hexadecimal representations are written there in a [[Monospaced font|typewriter typeface]]: {{mono|5A3}}, {{mono|C1F27ED}} In linear text systems, such as those used in most computer programming environments, a variety of methods have arisen:<!-- * * * These are ordered from most to least likely to be encountered by lay people * * * --> * {{anchor|_nix}}Although best known from the [[C (programming language)|C programming language]] (and the many languages influenced by C), the prefix <code>0x</code> to indicate a hex constant may have had origins in the [[IBM Stretch]] systems. It is derived from the <code>0</code> prefix already in use for [[octal]] constants. Byte values can be expressed in hexadecimal with the prefix <code>\x</code> followed by two hex digits: <code>'\x1B'</code> represents the [[Escape character|Esc]] control character; <code>"\x1B[0m\x1B[25;1H"</code> is a string containing 11 characters with two embedded Esc characters.<ref>The string <code>"\x1B[0m\x1B[25;1H"</code> specifies the character sequence {{mono|Esc [ 0 m Esc [ 2 5; 1 H}}. These are the escape sequences used on an [[ANSI escape code|ANSI terminal]] that reset the character set and color, and then move the cursor to line 25.</ref> To output an integer as hexadecimal with the [[printf]] function family, the format conversion code <code>%X</code> or <code>%x</code> is used. * In [[XML]] and [[XHTML]], characters can be expressed as hexadecimal [[numeric character reference]]s using the notation <code>&#x''code'';</code>, for instance <code>&#x0054;</code> represents the character U+0054 (the uppercase letter "T"). If there is no {{code|x}} the number is decimal (thus <code>&#0084;</code> is the same character).<ref>{{cite web|url=https://www.unicode.org/charts/PDF/U2000.pdf|title=The Unicode Standard, Version 7|website=Unicode|access-date=28 October 2018|archive-date=2016-03-03 |archive-url=https://web.archive.org/web/20160303175510/http://www.unicode.org/charts/PDF/U2000.pdf|url-status=live}}</ref> * {{anchor|Intel}}In Intel-derived [[assembly language]]s and Modula-2,<ref>{{cite web |title=Modula-2 β Vocabulary and representation |url=http://modula2.org/reference/vocabulary.php |website=Modula β2 |access-date=1 November 2015 |archive-date=2015-12-13 |archive-url=https://web.archive.org/web/20151213053318/http://www.modula2.org/reference/vocabulary.php |url-status=live }}</ref> hexadecimal is denoted with a suffixed {{mono|H}} or {{mono|h}}: <code>FFh</code> or <code>05A3H</code>. Some implementations require a leading zero when the first hexadecimal digit character is not a decimal digit, so one would write <code>0FFh</code> instead of <code>FFh</code>. Some other implementations (such as NASM) allow C-style numbers (<code>0x42</code>). * {{anchor|Motorola}}Other assembly languages ([[MOS Technology 6502|6502]], [[Motorola]]), [[Pascal (programming language)|Pascal]], [[Delphi (programming language)|Delphi]], some versions of [[BASIC]] ([[Commodore BASIC|Commodore]]), [[GameMaker Studio|GameMaker Language]], [[Godot (game engine)|Godot]] and [[Forth (programming language)|Forth]] use <code>$</code> as a prefix: <code>$5A3</code>, <code>$C1F27ED</code>. * Some assembly languages (Microchip) use the notation <code>H'ABCD'</code> (for ABCD<sub>16</sub>). Similarly, [[Fortran 95 language features|Fortran 95]] uses Z'ABCD'. * [[Ada (programming language)|Ada]] and [[VHDL]] enclose hexadecimal numerals in based "numeric quotes": <code>16#5A3#</code>, <code>16#C1F27ED#</code>. For bit vector constants [[VHDL]] uses the notation <code>x"5A3"</code>, <code>x"C1F27ED"</code>.<ref>{{cite web |url=https://www.fpgatutorial.com/vhdl-types-and-conversions#vhdl-assign-data |title=An Introduction to VHDL Data Types |website=FPGA Tutorial |date=10 May 2020 |access-date=2020-08-21 |archive-date=2020-08-23 |archive-url=https://web.archive.org/web/20200823094252/https://www.fpgatutorial.com/vhdl-types-and-conversions/#vhdl-assign-data |url-status=live }}</ref> * [[Verilog]] represents hexadecimal constants in the form <code>8'hFF</code>, where 8 is the number of bits in the value and FF is the hexadecimal constant. * The [[Icon (programming language)|Icon]] and [[Smalltalk]] languages use the prefix <code>16r</code>: <code>16r5A3</code> * [[PostScript]] and the [[Bourne shell]] and its derivatives denote hex with prefix <code>16#</code>: <code>16#5A3</code>, <code>16#C1F27ED</code>. * [[Common Lisp]] uses the prefixes <code>#x</code> and <code>#16r</code>. Setting the variables *read-base*<ref>{{cite web |title=*read-base* variable in Common Lisp |url=http://www.lispworks.com/documentation/HyperSpec/Body/v_rd_bas.htm |website=CLHS |access-date=2015-01-10 |archive-date=2016-02-03 |archive-url=https://web.archive.org/web/20160203221612/http://www.lispworks.com/documentation/HyperSpec/Body/v_rd_bas.htm |url-status=live }}</ref> and *print-base*<ref>{{cite web |title=*print-base* variable in Common Lisp |url=http://www.lispworks.com/documentation/HyperSpec/Body/v_pr_bas.htm#STprint-baseST |website=CLHS |access-date=2015-01-10 |archive-date=2014-12-26 |archive-url=https://web.archive.org/web/20141226172420/http://www.lispworks.com/documentation/HyperSpec/Body/v_pr_bas.htm#STprint-baseST |url-status=live }}</ref> to 16 can also be used to switch the reader and printer of a Common Lisp system to Hexadecimal number representation for reading and printing numbers. Thus Hexadecimal numbers can be represented without the #x or #16r prefix code, when the input or output base has been changed to 16. * [[MSX BASIC]],<ref>[http://www.atarimagazines.com/compute/issue56/107_1_MSX_IS_COMING.php MSX is Coming β Part 2: Inside MSX] {{Webarchive|url=https://web.archive.org/web/20101124111223/http://www.atarimagazines.com/compute/issue56/107_1_MSX_IS_COMING.php |date=2010-11-24 }} [[Compute!]], issue 56, January 1985, p. 52</ref> [[QuickBASIC]], [[FreeBASIC]] and [[Visual Basic]] prefix hexadecimal numbers with <code>&H</code>: <code>&H5A3</code> * [[BBC BASIC]] and [[Locomotive BASIC]] use <code>&</code> for hex.<ref>BBC BASIC programs are not fully portable to [[Microsoft BASIC]] (without modification) since the latter takes <code>&</code> to prefix [[octal]] values. (Microsoft BASIC primarily uses <code>&O</code> to prefix octal, and it uses <code>&H</code> to prefix hexadecimal, but the ampersand alone yields a default interpretation as an octal prefix.</ref> * [[TI-89]] and 92 series uses a <code>0h</code> prefix: <code>0h5A3</code>, <code>0hC1F27ED</code> * [[ALGOL 68]] uses the prefix <code>16r</code> to denote hexadecimal numbers: <code>16r5a3</code>, <code>16rC1F27ED</code>. Binary, quaternary (base-4), and octal numbers can be specified similarly. * The most common format for hexadecimal on IBM mainframes ([[zSeries]]) and midrange computers ([[IBM i]]) running the traditional OS's ([[z/OS|zOS]], [[VSE (operating system)|zVSE]], [[z/VM|zVM]], [[Transaction Processing Facility|TPF]], [[IBM i]]) is <code>X'5A3'</code> or <code>X'C1F27ED'</code>, and is used in Assembler, [[PL/I]], [[COBOL]], [[Job Control Language|JCL]], scripts, commands and other places. This format was common on other (and now obsolete) IBM systems as well. Occasionally quotation marks were used instead of apostrophes.
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)