In mathematics and computing, hexadecimal (also base 16, or hex) is a positional numeral system with a radix, or base, of 16. It uses sixteen distinct symbols, most often the symbols 0-9 to represent values zero to nine, and A-F (or alternatively a-f) to represent values ten to fifteen.


In mathematics, a subscript is typically used to specify the radix. For example the decimal value would be expressed in hexadecimal as 2AF316. In programming, a number of notations are used to support hexadecimal representation, usually involving a prefix or suffix. The prefix 0x is used in C and related languages, which would denote this value by 0x2AF3.


Written representation

Using 0-9 and A-F

0hex = 0dec = 0oct 0 0 0 0
1hex = 1dec = 1oct 0 0 0 1
2hex = 2dec = 2oct 0 0 1 0
3hex = 3dec = 3oct 0 0 1 1
4hex = 4dec = 4oct 0 1 0 0
5hex = 5dec = 5oct 0 1 0 1
6hex = 6dec = 6oct 0 1 1 0
7hex = 7dec = 7oct 0 1 1 1
8hex = 8dec = 10oct 1 0 0 0
9hex = 9dec = 11oct 1 0 0 1
Ahex = 10dec = 12oct 1 0 1 0
Bhex = 11dec = 13oct 1 0 1 1
Chex = 12dec = 14oct 1 1 0 0
Dhex = 13dec = 15oct 1 1 0 1
Ehex = 14dec = 16oct 1 1 1 0
Fhex = 15dec = 17oct 1 1 1 1



  • In URIs (including URLs), character codes are written as hexadecimal pairs prefixed with %: http://www.example.com/name%20with%20spaces where %20 is the space (blank) character, ASCII code point 20 in hex, 32 in decimal.
  • In XML and XHTML, characters can be expressed as hexadecimal numeric character references using the notation &#xcode;, where the x denotes that code is a hex code point (of 1- to 6-digits) assigned to the character in the Unicode standard. Thus &#x2019; represents the right single quotation mark ('), Unicode code point number 2019 in hex, 8217 (thus &#8217; in decimal).[1]
  • Color references in HTML, CSS and X Window can be expressed with six hexadecimal digits (two each for the red, green and blue components, in that order) prefixed with #: white, for example, is represented #FFFFFF .[2] CSS allows 3-hexdigit abbreviations with one hexdigit per component: #FA3 abbreviates #FFAA33 (a golden orange:     ).
  • In Intel-derived assembly languages and Modula-2,[4] hexadecimal is denoted with a suffixed H or h: FFh or 05A3H. Some implementations require a leading zero when the first hexadecimal digit character is not a decimal digit, so one would write 0FFh instead of FFh
  • Other assembly languages (6502, Motorola), Pascal, Delphi, some versions of BASIC (Commodore), Game Maker Language, Godot and Forth use $ as a prefix: $5A3.
  • The Smalltalk language uses the prefix 16r: 16r5A3
  • Common Lisp uses the prefixes #x and #16r. Setting the variables *read-base*[6] and *print-base*[7] to 16 can also 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,[8]QuickBASIC, FreeBASIC and Visual Basic prefix hexadecimal numbers with &H: &H5A3
  • BBC BASIC and Locomotive BASIC use & for hex.[9]
  • Donald Knuth introduced the use of a particular typeface to represent a particular radix in his book The TeXbook.[10] Hexadecimal representations are written there in a typewriter typeface: 5A3
  • Any IPv6 address can be written as eight groups of four hexadecimal digits (sometimes called hextets), where each group is separated by a colon (:). This, for example, is a valid IPv6 address: 2001:0db8:85a3:0000:0000:8a2e:0370:7334; this can be abbreviated as 2001:db8:85a3::8a2e:370:7334. By contrast, IPv4 addresses are usually written in decimal.


History of written representations

Bruce Alan Martin's hexadecimal notation proposal[11]


Verbal and digital representations


Hexadecimal finger-counting scheme.

Systems of counting on digits have been devised for both binary and hexadecimal. Arthur C. Clarke suggested using each finger as an on/off bit, allowing finger counting from zero to 102310 on ten fingers.[] Another system for counting up to FF16 (25510) is illustrated on the right.


The hexadecimal system can express negative numbers the same way as in decimal: -2A to represent -4210 and so on.


Hexadecimal exponential notation


Usually the number is normalised so that the leading hexadecimal digit is 1 (unless the value is exactly 0).

Example: 1.3DEp42 represents 1.3DE16 × 242.

Hexadecimal exponential notation is required by the IEEE 754-2008 binary floating-point standard. This notation can be used for floating-point literals in the C99 edition of the C programming language.[17] Using the %a or %A conversion specifiers, this notation can be produced by implementations of the printf family of functions following the C99 specification[18] and Single Unix Specification (IEEE Std 1003.1) POSIX standard.[19]


Binary conversion


  • 00012 = 110
  • 00102 = 210
  • 01002 = 410
  • 10002 = 810


11112 = 810 + 410 + 210 + 110
  = 1510



  = 38792210


010111101011010100102 = 0101  1110  1011  0101  00102
  = 5 E B 5 216
  = 5EB5216

The conversion from hexadecimal to binary is equally direct.

Other simple conversions



Division-remainder in source base



  1. i
  2. hi
  3. d i) / 16



function toHex(d) {
  var r = d % 16;
  if (d - r == 0) {
    return toChar(r);

function toChar(n) {
  const alpha = "0123456789ABCDEF";
  return alpha.charAt(n);

Addition and multiplication

A hexadecimal multiplication table

It is also possible to make the conversion by assigning each place in the source base the hexadecimal representation of its place value and then performing multiplication and addition to get the final representation. That is, to convert the number B3AD to decimal one can split the hexadecimal number into its digits: B (1110), 3 (310), A (1010) and D (1310), and then get the final result by multiplying each decimal representation by 16p, where p is the corresponding hex digit position, counting from right to left, beginning with 0. In this case we have B3AD = (11 × 163) + (3 × 162) + (10 × 161) + (13 × 160), which is 45997 base 10.

Tools for conversion

Most modern computer systems with graphical user interfaces provide a built-in calculator utility, capable of performing conversions between various radices, in general including hexadecimal.


Real numbers

Rational numbers

As with other numeral systems, the hexadecimal system can be used to represent rational numbers, although repeating expansions are common since sixteen (10hex) has only a single prime factor (two):

1/2 = 0.8
1/3 = 0.5
1/4 = 0.4
1/5 = 0.3
1/6 = 0.2A
1/7 = 0.249
1/8 = 0.2
1/9 = 0.1C7
1/A = 0.19
1/B = 0.1745D
1/C = 0.15
1/D = 0.13B
1/E = 0.1249
1/F = 0.1
1/10 = 0.1
1/11 = 0.0F

where an overline denotes a recurring pattern.



n Decimal
Prime factors of base, b = 10: 2, 5; b - 1 = 9: 3; b + 1 = 11: 11
Prime factors of base, b = 1610 = 10: 2; b - 1 = 1510 = F: 3, 5; b + 1 = 1710 = 11: 11
2 1/2 2 0.5 0.8 2 1/2
4 1/4 2 0.25 0.4 2 1/4
5 1/5 5 0.2 0.3 5 1/5
7 1/7 7 0.142857 0.249 7 1/7
8 1/8 2 0.125 0.2 2 1/8
9 1/9 3 0.1 0.1C7 3 1/9
11 1/11 11 0.09 0.1745D B 1/B
13 1/13 13 0.076923 0.13B D 1/D
16 1/16 2 0.0625 0.1 2 1/10
17 1/17 17 0.0588235294117647 0.0F 11 1/11
19 1/19 19 0.052631578947368421 0.0D79435E5 13 1/13
23 1/23 23 0.0434782608695652173913 0.0B21642C859 17 1/17
25 1/25 5 0.04 0.0A3D7 5 1/19
27 1/27 3 0.037 0.097B425ED 3 1/1B
29 1/29 29 0.0344827586206896551724137931 0.08D3DCB 1D 1/1D
31 1/31 31 0.032258064516129 0.08421 1F 1/1F
32 1/32 2 0.03125 0.08 2 1/20

Irrational numbers


Number Positional representation
Decimal Hexadecimal
(the length of the diagonal of a unit square) ... 1.6A09E667F3BCD...
(the length of the diagonal of a unit cube) ... 1.BB67AE8584CAA...
(the length of the diagonal of a 1×2 rectangle) ... 2.3C6EF372FE95...
? (phi, the golden ratio = (1+)/2) ... 1.9E3779B97F4A...
? (pi, the ratio of circumference to diameter of a circle)
e (the base of the natural logarithm) ... 2.B7E151628AED2A6B...
? (the Thue-Morse constant) ... 0.6996 9669 9669 6996...
? (the limiting difference between the
harmonic series and the natural logarithm)
... 0.93C467E37DB0C7A4D1B...



2x Value Value (Decimal)
20 1 1
21 2 2
22 4 4
23 8 8
24 10hex 16dec
25 20hex 32dec
26 40hex 64dec
27 80hex 128dec
28 100hex 256dec
29 200hex 512dec
2A (210dec) 400hex 1024dec
2B (211dec) 800hex 2048dec
2C (212dec) 1000hex 4096dec
2D (213dec) 2000hex 8192dec
2E (214dec) 4000hex 16,384dec
2F (215dec) 8000hex 32,768dec
210 (216dec) 10000hex 65,536dec



The word hexadecimal is composed of hexa-, derived from the Greek (hex) for six, and -decimal, derived from the Latin for tenth. Webster's Third New International online derives hexadecimal as an alteration of the all-Latin sexadecimal (which appears in the earlier Bendix documentation). The earliest date attested for hexadecimal in Merriam-Webster Collegiate online is 1954, placing it safely in the category of international scientific vocabulary (ISV). It is common in ISV to mix Greek and Latin combining forms freely. The word sexagesimal (for base 60) retains the Latin prefix. Donald Knuth has pointed out that the etymologically correct term is senidenary (or possibly, sedenary), from the Latin term for grouped by 16. (The terms binary, ternary and quaternary are from the same Latin construction, and the etymologically correct terms for decimal and octal arithmetic are denary and octonary, respectively.)[20] Alfred B. Taylor used senidenary in his mid-1800s work on alternative number bases, although he rejected base 16 because of its "incommodious number of digits".[21][22] Schwartzman notes that the expected form from usual Latin phrasing would be sexadecimal, but computer hackers would be tempted to shorten that word to sex.[23] The etymologically proper Greek term would be hexadecadic / / hexadekadikós (although in Modern Greek, decahexadic / / dekaexadikos is more commonly used).

Use in Chinese culture

The traditional Chinese units of weight were base-16. For example, one j?n (?) in the old system equals sixteen taels. The suanpan (Chinese abacus) could be used to perform hexadecimal calculations.

Primary numeral system

As with the duodecimal system, there have been occasional attempts to promote hexadecimal as the preferred numeral system. These attempts often propose specific pronunciation and symbols for the individual numerals.[24] Some proposals unify standard measures so that they are multiples of 16.[25][26][27]


Transfer encoding

Base16 or hex (not to be confused with Intel HEX and the like) is one of the simplest binary-to-text encodings, which stores each byte as a pair of hexadecimal digits. Many variations of such format are possible, for example either uppercase (A-F) or lowercase (a-f) letters may be used for digits greater than 9; spaces, line breaks or other separators may be added between digit groups of different lengths; header and/or footer with metainformation may be added.

See also


  1. ^ "PDF The Unicode Standard, Version 7" (PDF). 
  2. ^ "Hexadecimal web colors explained". 
  4. ^ "Modula-2 - Vocabulary and representation". Modula -2. Retrieved 2015. 
  6. ^ "*read-base* variable in Common Lisp". 
  7. ^ "*print-base* variable in Common Lisp". 
  8. ^ MSX is Coming -- Part 2: Inside MSX Compute!, issue 56, January 1985, p. 52
  10. ^ Donald E. Knuth. The TeXbook (Computers and Typesetting, Volume A). Reading, Massachusetts: Addison-Wesley, 1984. ISBN 0-201-13448-9. The source code of the book in TeX Archived 2007-09-27 at the Wayback Machine. (and a required set of macros CTAN.org) is available online on CTAN.
  13. ^ Gill, S.; Neagher, R. E.; Muller, D. E.; Nash, J. P.; Robertson, J. E.; Shapin, T.; Whesler, D. J. (1956-09-01). Nash, J. P., ed. "ILLIAC Programming - A Guide to the Preparation of Problems For Solution by the University of Illinois Digital Computer" (PDF) (Fourth printing. Revised and corrected ed.). Urbana, Illinois, USA: Digital Computer Laboratory, Graduate College, University of Illinois. pp. 3-2. Archived (PDF) from the original on 2017-05-31. Retrieved . 
  14. ^ ROYAL PRECISION Electronic Computer LGP - 30 PROGRAMMING MANUAL. Port Chester, New York: Royal McBee Corporation. April 1957. Archived from the original on 2017-05-31. Retrieved .  (NB. This somewhat odd sequence was from the next six sequential numeric keyboard codes in the LGP-30's 6-bit character code.)
  16. ^ BCD-to-Seven-Segment Decoders/Drivers: SN54246/SN54247/SN54LS247, SN54LS248 SN74246/SN74247/SN74LS247/SN74LS248 (PDF), Texas Instruments, March 1988 [March 1974], SDLS083, archived (PDF) from the original on 2017-03-29, retrieved , [...] They can be used interchangeable in present or future designs to offer designers a choice between two indicator fonts. The '46A, '47A, 'LS47, and 'LS48 compose the 6 and the 9 without tails and the '246, '247, 'LS247, and 'LS248 compose the 6 and the 0 with tails. Composition of all other characters, including display patterns for BCD inputs above nine, is identical. [...] Display patterns for BCD input counts above 9 are unique symbols to authenticate input conditions. [...] 
  17. ^ "ISO/IEC 9899:1999 - Programming languages - C". Iso.org. 2011-12-08. Retrieved . 
  18. ^ "Rationale for International Standard - Programming Languages - C" (PDF). 5.10. April 2003. pp. 52, 153-154, 159. Archived (PDF) from the original on 2016-06-06. Retrieved . 
  24. ^ "Base 4^2 Hexadecimal Symbol Proposal". 
  25. ^ "Intuitor Hex Headquarters". 
  26. ^ "A proposal for addition of the six Hexadecimal digits (A-F) to Unicode". 




Connect with defaultLogic
What We've Done
Led Digital Marketing Efforts of Top 500 e-Retailers.
Worked with Top Brands at Leading Agencies.
Successfully Managed Over $50 million in Digital Ad Spend.
Taught Advanced Internet Marketing Strategies at the graduate level.


Visit defaultLogic's partner sites below:
PopFlock.com : Music Genres | Musicians | Musical Instruments | Music Industry

  Contact Us