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!
===Written representation=== In most current use cases, the letters A–F or a–f represent the values 10–15, while the [[Arabic numerals|numerals]] 0–9 are used to represent their decimal values. There is no universal convention to use lowercase or uppercase, so each is prevalent or preferred in particular environments by community standards or convention; even mixed case is used. Some [[seven-segment display]]s use mixed-case 'A b C d E F' to distinguish the digits A–F from one another and from 0–9. There is some standardization of using spaces (rather than commas or another punctuation mark) to separate hex values in a long list. For instance, in the following [[hex dump]], each 8-bit [[byte]] is a 2-digit hex number, with spaces between them, while the 32-bit offset at the start is an 8-digit hex number. <div class="nowrap"><syntaxhighlight lang="hexdump"> 00000000 57 69 6B 69 70 65 64 69 61 2C 20 74 68 65 20 66 00000010 72 65 65 20 65 6E 63 79 63 6C 6F 70 65 64 69 61 00000020 20 74 68 61 74 20 61 6E 79 6F 6E 65 20 63 61 6E 00000030 20 65 64 69 74 2C 20 69 6E 63 6C 75 64 69 6E 67 00000040 20 79 6F 75 20 28 61 6E 64 20 6D 65 29 21 </syntaxhighlight></div> ====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. ====Syntax that is always Hex==== Sometimes the numbers are known to be Hex. * In [[URI]]s (including [[URL]]s), [[character encoding|character codes]] are written as hexadecimal pairs prefixed with {{code|%}}: {{code|<nowiki>http://www.example.com/name%20with%20spaces</nowiki>}} where {{code|%20}} is the code for the [[Space (punctuation)#Space characters and digital typography|space (blank)]] character, [[ASCII]] code point 20 in hex, 32 in decimal. * In the [[Unicode]] standard, a character value is represented with {{code|U+}} followed by the hex value, e.g. {{code|U+00A1}} is the [[inverted exclamation point]] (¡). * [[Web colors|Color references]] in HTML, [[Cascading Style Sheets|CSS]] and [[X window system|X Window]] can be expressed with six hexadecimal digits (two each for the red, green and blue components, in that order) prefixed with {{code|#}}: <span style="color:#FF00FF">magenta</span>, for example, is represented as {{code|#FF00FF}}.<ref>{{cite web |url=http://www.web-colors-explained.com/hex.php |title=Hexadecimal web colors explained |access-date=2006-01-11 |archive-url=https://web.archive.org/web/20060422004336/http://www.web-colors-explained.com/hex.php |archive-date=2006-04-22 |url-status=dead }}</ref> CSS also allows 3-hexdigit abbreviations with one hexdigit per component: {{code|#FA3}} abbreviates {{code|#FFAA33}} (a golden orange: {{color box|#FA3}}). * In [[MIME]] (e-mail extensions) [[quoted-printable]] encoding, character codes are written as hexadecimal pairs prefixed with {{code|1==}}: {{code|1=Espa=F1a}} is "España" (F1{{sub|hex}} is the code for ''ñ'' in the ISO/IEC 8859-1 character set).<ref>{{Cite web |url=https://www.ic.unicamp.br/~stolfi/EXPORT/www/ISO-8859-1-Encoding.html|title=ISO-8859-1 (ISO Latin 1) Character Encoding |website=www.ic.unicamp.br|access-date=2019-06-26|archive-date=2019-06-29 |archive-url=https://web.archive.org/web/20190629203430/http://www.ic.unicamp.br/~stolfi/EXPORT/www/ISO-8859-1-Encoding.html|url-status=live}}</ref>) * PostScript binary data (such as image [[pixel]]s) can be expressed as unprefixed consecutive hexadecimal pairs: {{code|AA213FD51B3801043FBC}} ... * Any [[IPv6 address]] can be written as eight groups of four hexadecimal digits (sometimes called [[hextet (computing)|hextet]]s), where each group is separated by a colon ({{code|:}}). This, for example, is a valid IPv6 address: {{code|2001:0db8:85a3:0000:0000:8a2e:0370:7334}} or abbreviated by removing leading zeros as {{code|2001:db8:85a3::8a2e:370:7334}} ([[IPv4 address]]es are usually written in decimal). * [[Globally unique identifier]]s are written as thirty-two hexadecimal digits, often in unequal hyphen-separated groupings, for example {{code|3F2504E0-4F89-41D3-9A0C-0305E82C3301}}.
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)