Hexadecimal

Overview

Mathematics

Mathematics is the study of quantity, space, structure, and change. Mathematicians seek out patterns and formulate new conjectures. Mathematicians resolve the truth or falsity of conjectures by mathematical proofs, which are arguments sufficient to convince other mathematicians of their validity...

and computer science

Computer science

Computer science or computing science is the study of the theoretical foundations of information and computation and of practical techniques for their implementation and application in computer systems...

,

**hexadecimal**(also

**base**

, or

Radix

In mathematical numeral systems, the base or radix for the simplest case is the number of unique digits, including zero, that a positional numeral system uses to represent numbers. For example, for the decimal system the radix is ten, because it uses the ten digits from 0 through 9.In any numeral...

**hex**) is a positional

Positional notation

Positional notation or place-value notation is a method of representing or encoding numbers. Positional notation is distinguished from other notations for its use of the same symbol for the different orders of magnitude...

numeral system

Numeral system

A numeral system is a writing system for expressing numbers, that is a mathematical notation for representing numbers of a given set, using graphemes or symbols in a consistent manner....

with a radix

Radix

In mathematical numeral systems, the base or radix for the simplest case is the number of unique digits, including zero, that a positional numeral system uses to represent numbers. For example, for the decimal system the radix is ten, because it uses the ten digits from 0 through 9.In any numeral...

, or base, of 16. It uses sixteen distinct symbols, most often the symbols

**0**–

**9**to represent values zero to nine, and

**A**,

**B**,

**C**,

**D**,

**E**,

**F**(or alternatively

**a**–

**f**) to represent values ten to fifteen. For example, the hexadecimal number 2AF3 is equal, in decimal, to (2 × 16

^{3}) + (10 × 16

^{2}) + (15 × 16

^{1}) + (3 × 16

^{0}), or 10,995.

Each hexadecimal digit represents four binary digits (bit

Bit

A bit is the basic unit of information in computing and telecommunications; it is the amount of information stored by a digital device or other physical system that exists in one of two possible distinct states...

s) (also called a "nibble

Nibble

In computing, a nibble is a four-bit aggregation, or half an octet...

"), and the primary use of hexadecimal notation is as a human-friendly representation of binary-coded

Binary code

A binary code is a way of representing text or computer processor instructions by the use of the binary number system's two-binary digits 0 and 1. This is accomplished by assigning a bit string to each particular symbol or instruction...

values in computing and digital electronics.

Unanswered Questions

Discussions

Encyclopedia

In mathematics

and computer science

,

numeral system

with a radixIn mathematical numeral systems, the base or radix for the simplest case is the number of unique digits, including zero, that a positional numeral system uses to represent numbers. For example, for the decimal system the radix is ten, because it uses the ten digits from 0 through 9.In any numeral...

, or base, of 16. It uses sixteen distinct symbols, most often the symbols

Each hexadecimal digit represents four binary digits (bit

s) (also called a "nibble

"), and the primary use of hexadecimal notation is as a human-friendly representation of binary-coded

values in computing and digital electronics. For example, byte

values can range from 0 to 255 (decimal) but may be more conveniently represented as two hexadecimal digits in the range 00 through FF. Hexadecimal is also commonly used to represent computer memory address

es.

In linear text systems, such as those used in most computer programming environments, a variety of methods have arisen:

Mathematics

Mathematics is the study of quantity, space, structure, and change. Mathematicians seek out patterns and formulate new conjectures. Mathematicians resolve the truth or falsity of conjectures by mathematical proofs, which are arguments sufficient to convince other mathematicians of their validity...

and computer science

Computer science

Computer science or computing science is the study of the theoretical foundations of information and computation and of practical techniques for their implementation and application in computer systems...

,

**hexadecimal**(also**base**

, orRadix

In mathematical numeral systems, the base or radix for the simplest case is the number of unique digits, including zero, that a positional numeral system uses to represent numbers. For example, for the decimal system the radix is ten, because it uses the ten digits from 0 through 9.In any numeral...

**hex**) is a positionalPositional notation

Positional notation or place-value notation is a method of representing or encoding numbers. Positional notation is distinguished from other notations for its use of the same symbol for the different orders of magnitude...

numeral system

Numeral system

A numeral system is a writing system for expressing numbers, that is a mathematical notation for representing numbers of a given set, using graphemes or symbols in a consistent manner....

with a radix

Radix

, or base, of 16. It uses sixteen distinct symbols, most often the symbols

**0**–**9**to represent values zero to nine, and**A**,**B**,**C**,**D**,**E**,**F**(or alternatively**a**–**f**) to represent values ten to fifteen. For example, the hexadecimal number 2AF3 is equal, in decimal, to (2 × 16^{3}) + (10 × 16^{2}) + (15 × 16^{1}) + (3 × 16^{0}), or 10,995.Each hexadecimal digit represents four binary digits (bit

Bit

A bit is the basic unit of information in computing and telecommunications; it is the amount of information stored by a digital device or other physical system that exists in one of two possible distinct states...

s) (also called a "nibble

Nibble

In computing, a nibble is a four-bit aggregation, or half an octet...

"), and the primary use of hexadecimal notation is as a human-friendly representation of binary-coded

Binary code

A binary code is a way of representing text or computer processor instructions by the use of the binary number system's two-binary digits 0 and 1. This is accomplished by assigning a bit string to each particular symbol or instruction...

values in computing and digital electronics. For example, byte

Byte

The byte is a unit of digital information in computing and telecommunications that most commonly consists of eight bits. Historically, a byte was the number of bits used to encode a single character of text in a computer and for this reason it is the basic addressable element in many computer...

values can range from 0 to 255 (decimal) but may be more conveniently represented as two hexadecimal digits in the range 00 through FF. Hexadecimal is also commonly used to represent computer memory address

Memory address

A digital computer's memory, more specifically main memory, consists of many memory locations, each having a memory address, a number, analogous to a street address, at which computer programs store and retrieve, machine code or data. Most application programs do not directly read and write to...

es.

## Representing hexadecimal

In situations where there is no context, 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_{10}is decimal 159; 159_{16}is hexadecimal 159, which is equal to 345_{10}. Other authors prefer a text subscript, such as 159_{decimal}and 159_{hex}, or 159_{d}and 159_{h}.In linear text systems, such as those used in most computer programming environments, a variety of methods have arisen:

- In URLs, character codes are written as hexadecimal pairs prefixed with
`%`

:

wherehttp://www.example.com/name%20with%20spaces `%20`

is the space (blank) character (code value 20 in hex, 32 in decimal). - In XMLXMLExtensible Markup Language is a set of rules for encoding documents in machine-readable form. It is defined in the XML 1.0 Specification produced by the W3C, and several other related specifications, all gratis open standards....

and XHTMLXHTMLXHTML is a family of XML markup languages that mirror or extend versions of the widely-used Hypertext Markup Language , the language in which web pages are written....

, characters can be expressed as hexadecimal numeric character references using the notation`&#x`

, where*code*;*code*is the 1- to 6-digit hex number assigned to the character in the UnicodeUnicodeUnicode is a computing industry standard for the consistent encoding, representation and handling of text expressed in most of the world's writing systems...

standard. Thus`’`

represents the curled right single quote (Unicode value 2019 in hex, 8217 in decimal). - Color references in HTML and CSSCascading Style SheetsCascading Style Sheets is a style sheet language used to describe the presentation semantics of a document written in a markup language...

and X WindowX Window SystemThe X window system is a computer software system and network protocol that provides a basis for graphical user interfaces and rich input device capability for networked computers...

can be expressed with six hexdigits (two each for the red, green, and blue components, in that order) prefixed with`#`

: white, for example, is represented`#FFFFFF`

. CSS allows 3-hexdigit abbreviations with one hexdigit per component: #FA3 abbreviates #FFAA33 (a golden orange: ). - *nix (Unix and related) shells, and likewise the C programming languageC (programming language)C is a general-purpose computer programming language developed between 1969 and 1973 by Dennis Ritchie at the Bell Telephone Laboratories for use with the Unix operating system....

, which was designed for Unix (and the syntactic descendants of C) use the prefix`0x`

for numeric constants represented in hex:`0x5A3`

. Character and string constants may express character codes in hexadecimal with the prefix`\x`

followed by two hex digits:`'\x1B'`

represents the EscEscape characterIn computing and telecommunication, an escape character is a character which invokes an alternative interpretation on subsequent characters in a character sequence. An escape character is a particular case of metacharacters...

control character;`"\x1B[0m\x1B[25;1H"`

is a string containing 11 characters (plus a trailing NUL to mark the end of the string) with two embedded Esc characters. To output an integer as hexadecimal with the printfPrintfPrintf format string refers to a control parameter used by a class of functions typically associated with some types of programming languages. The format string specifies a method for rendering an arbitrary number of varied data type parameter into a string...

function family, the format conversion code`%X`

or`%x`

is used. - In the UnicodeUnicodeUnicode is a computing industry standard for the consistent encoding, representation and handling of text expressed in most of the world's writing systems...

standard, a character value is represented with`U+`

`followed by the hex value:`

`U+20AC`

is the Euro signEuro signThe euro sign is the currency sign used for the euro, the official currency of the Eurozone in the European Union . The design was presented to the public by the European Commission on 12 December 1996. The international three-letter code for the euro is EUR...

(€). - In MIMEMIMEMultipurpose Internet Mail Extensions is an Internet standard that extends the format of email to support:* Text in character sets other than ASCII* Non-text attachments* Message bodies with multiple parts...

(e-mail extensions) quoted-printableQuoted-printableQuoted-printable, or QP encoding, is an encoding using printable ASCII characters to transmit 8-bit data over a 7-bit data path or, generally, over a medium which is not 8-bit clean...

encoding, characters that cannot be represented as literal ASCIIASCIIThe American Standard Code for Information Interchange is a character-encoding scheme based on the ordering of the English alphabet. ASCII codes represent text in computers, communications equipment, and other devices that use text...

characters are represented by their codes as two hexadecimal digits (in ASCII) prefixed by an*equal to*sign`=`

, as in`Espa=F1a`

to send "España" (Spain). (Hexadecimal F1, equal to decimal 241, is the code number for the lower case n with tilde in the ISO/IEC 8859-1 character set.) - In Intel-derived assembly languageAssembly languageAn assembly language is a low-level programming language for computers, microprocessors, microcontrollers, and other programmable devices. It implements a symbolic representation of the machine codes and other constants needed to program a given CPU architecture...

s, 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:`0FFh`

- Other assembly languages (6502MOS Technology 6502The MOS Technology 6502 is an 8-bit microprocessor that was designed by Chuck Peddle and Bill Mensch for MOS Technology in 1975. When it was introduced, it was the least expensive full-featured microprocessor on the market by a considerable margin, costing less than one-sixth the price of...

, AT&TAT&TAT&T Inc. is an American multinational telecommunications corporation headquartered in Whitacre Tower, Dallas, Texas, United States. It is the largest provider of mobile telephony and fixed telephony in the United States, and is also a provider of broadband and subscription television services...

, MotorolaMotorolaMotorola, Inc. was an American multinational telecommunications company based in Schaumburg, Illinois, which was eventually divided into two independent public companies, Motorola Mobility and Motorola Solutions on January 4, 2011, after losing $4.3 billion from 2007 to 2009...

), PascalPascal (programming language)Pascal is an influential imperative and procedural programming language, designed in 1968/9 and published in 1970 by Niklaus Wirth as a small and efficient language intended to encourage good programming practices using structured programming and data structuring.A derivative known as Object Pascal...

, DelphiObject PascalObject Pascal refers to a branch of object-oriented derivatives of Pascal, mostly known as the primary programming language of Embarcadero Delphi.-Early history at Apple:...

, some versions of BASICBASICBASIC is a family of general-purpose, high-level programming languages whose design philosophy emphasizes ease of use - the name is an acronym from Beginner's All-purpose Symbolic Instruction Code....

(CommodoreCommodore BASICCommodore BASIC, also known as PET BASIC, is the dialect of the BASIC programming language used in Commodore International's 8-bit home computer line, stretching from the PET of 1977 to the C128 of 1985...

) and Forth use`$`

as a prefix:`$5A3`

. - Some assembly languages (Microchip) use the notation
`H'ABCD'`

(for ABCD_{16}). - AdaAda (programming language)Ada is a structured, statically typed, imperative, wide-spectrum, and object-oriented high-level computer programming language, extended from Pascal and other languages...

and VHDL enclose hexadecimal numerals in based "numeric quotes":`16#5A3#`

. For bit vector constants VHDL uses the notation`x"5A3"`

. - VerilogVerilogIn the semiconductor and electronic design industry, Verilog is a hardware description language used to model electronic systems. Verilog HDL, not to be confused with VHDL , is most commonly used in the design, verification, and implementation of digital logic chips at the register-transfer level...

represents hexadecimal constants in the form`8'hFF`

, where 8 is the number of bits in the value and FF is the hexadecimal constant. - Modula-2Modula-2Modula-2 is a computer programming language designed and developed between 1977 and 1980 by Niklaus Wirth at ETH Zurich as a revision of Pascal to serve as the sole programming language for the operating system and application software for the personal workstation Lilith...

and some other languages use # as a prefix:`#05A3`

- The SmalltalkSmalltalkSmalltalk is an object-oriented, dynamically typed, reflective programming language. Smalltalk was created as the language to underpin the "new world" of computing exemplified by "human–computer symbiosis." It was designed and created in part for educational use, more so for constructionist...

language uses the prefix`16r`

:`16r5A3`

- PostScriptPostScriptPostScript is a dynamically typed concatenative programming language created by John Warnock and Charles Geschke in 1982. It is best known for its use as a page description language in the electronic and desktop publishing areas. Adobe PostScript 3 is also the worldwide printing and imaging...

denotes hex with prefix`16#`

:`16#5A3`

. Binary data (such as image pixelPixelIn digital imaging, a pixel, or pel, is a single point in a raster image, or the smallest addressable screen element in a display device; it is the smallest unit of picture that can be represented or controlled....

s) can be expressed as unprefixed consecutive hexadecimal pairs:`AA213FD51B3801043FBC`

... - In early systems when a MacintoshMacintoshThe Macintosh , or Mac, is a series of several lines of personal computers designed, developed, and marketed by Apple Inc. The first Macintosh was introduced by Apple's then-chairman Steve Jobs on January 24, 1984; it was the first commercially successful personal computer to feature a mouse and a...

crashed, one or two lines of hexadecimal code would be displayed under the Sad Mac to tell the user what went wrong. - Common LispCommon LispCommon Lisp, commonly abbreviated CL, is a dialect of the Lisp programming language, published in ANSI standard document ANSI INCITS 226-1994 , . From the ANSI Common Lisp standard the Common Lisp HyperSpec has been derived for use with web browsers...

use the prefixes`#x`

and`#16r`

. - MSX BASICMSX BASICMSX BASIC is a dialect of the BASIC programming language. It is an extended version of Microsoft Standard BASIC Version 4.5, and includes support for graphic, music, and various peripherals attached to MSX Personal Computers. Generally, MSX-BASIC is designed to follow GW-BASIC, which is one of the...

, QuickBASICQuickBASICMicrosoft QuickBASIC is an Integrated Development Environment and compiler for the BASIC programming language that was developed by Microsoft. QuickBASIC runs mainly on DOS, though there was a short-lived version for Mac OS...

, FreeBASICFreeBASICFreeBASIC is a free/open source , 32-bit BASIC compiler for Microsoft Windows, protected-mode DOS , Linux, FreeBSD and Xbox....

and Visual BasicVisual BasicVisual Basic is the third-generation event-driven programming language and integrated development environment from Microsoft for its COM programming model...

prefix hexadecimal numbers with`&H`

:`&H5A3`

- BBC BASICBBC BASICBBC BASIC is a programming language, developed in 1981 as a native programming language for the MOS Technology 6502 based Acorn BBC Micro home/personal computer, mainly by Sophie Wilson. It is a version of the BASIC programming language adapted for a U.K...

and Locomotive BASICLocomotive BASICLocomotive Basic is a proprietary dialect of the BASIC programming language written by Locomotive Software used only on the Amstrad CPC...

use`&`

for hex. - TI-89 and 92 series uses a
`0h`

prefix:`0h5A3`

- The most common format for hexadecimal on IBM mainframes (zSeriesZSeriesIBM System z, or earlier IBM eServer zSeries, is a brand name designated by IBM to all its mainframe computers.In 2000, IBM rebranded the existing System/390 to IBM eServer zSeries with the e depicted in IBM's red trademarked symbol, but because no specific machine names were changed for...

) and midrange computers (IBM System iIBM System iThe IBM System i is IBM's previous generation of midrange computer systems for IBM i users, and was subsequently replaced by the IBM Power Systems in April 2008....

) running the traditional OS's (zOSZ/OSz/OS is a 64-bit operating system for mainframe computers, produced by IBM. It derives from and is the successor to OS/390, which in turn followed a string of MVS versions.Starting with earliest:*OS/VS2 Release 2 through Release 3.8...

, zVSE, zVMZ/VMz/VM is the current version in IBM's VM family of virtual machine operating systems. z/VM was first released in October 2000 and remains in active use and development . It is directly based on technology and concepts dating back to the 1960s, with IBM's CP/CMS on the IBM System/360-67...

, TPFTransaction Processing FacilityTPF is an IBM real-time operating system for mainframes descended from the IBM System/360 family, including zSeries and System z9. The name is an initialism for Transaction Processing Facility....

, IBM i) is`X'5A3'`

, and is used in Assembler, PL/IPL/IPL/I is a procedural, imperative computer programming language designed for scientific, engineering, business and systems programming applications...

, CobolCOBOLCOBOL is one of the oldest programming languages. Its name is an acronym for COmmon Business-Oriented Language, defining its primary domain in business, finance, and administrative systems for companies and governments....

, JCLJob Control LanguageJob Control Language is a scripting language used on IBM mainframe operating systems to instruct the system on how to run a batch job or start a subsystem....

, 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. - Donald KnuthDonald KnuthDonald Ervin Knuth is a computer scientist and Professor Emeritus at Stanford University.He is the author of the seminal multi-volume work The Art of Computer Programming. Knuth has been called the "father" of the analysis of algorithms...

introduced the use of a particular typeface to represent a particular radix in his book*The TeXbook*. Hexadecimal representations are written there in a typewriter typeface:`5A3` - Any IPv6 addressIPv6 addressAn Internet Protocol Version 6 address is a numerical label that is used to identify a network interface of a computer or other network node participating in an IPv6-enabled computer network....

can be written as eight groups of four hexadecimal digits, where each group is separated by a colon (`:`

). This, for example, is a valid IPv6 address: 2001:0db8:85a3:0000:0000:8a2e:0370:7334 - ALGOL 68ALGOL 68ALGOL 68 isan imperative computerprogramming language that was conceived as a successor to theALGOL 60 programming language, designed with the goal of a...

uses the prefix`16r`

to denote hexadecimal numbers:`16r5a3`

. Binary, quaternary (base-4) and octal numbers can be specified similarly.

```
```

```
```

There is no universal convention to use lowercase or uppercase for the letter digits, and each is prevalent or preferred in particular environments by community standards or convention.

### Early representations

The choice of the letters *A* through *F* to represent the digits above nine was not universal in the early history of computers.
- During the 1950s, some installations favored using the digits 0 through 5 with a macronMacronA macron, from the Greek , meaning "long", is a diacritic placed above a vowel . It was originally used to mark a long or heavy syllable in Greco-Roman metrics, but now marks a long vowel...

character ("¯") to denote the values 10–15.
- Users of Bendix G-15Bendix G-15The Bendix G-15 computer was introduced in 1956 by the Bendix Corporation, Computer Division, Los Angeles, California. It was about 5 by 3 by 3 ft and weighed about 950 lb . The base system, without peripherals, cost $49,500. A working model cost around $60,000. It could also be rented for...

computers used the letters *U* through *Z*.
- The Librascope LGP-30LGP-30The LGP-30, standing for Librascope General Purpose and then Librascope General Precision, was an early off-the-shelf computer. It was manufactured by the Librascope company of Glendale, California , and sold and serviced by the Royal Precision Electronic Computer Company, a joint venture with the...

used the letters *F*, *G*, *J*, *K*, *Q* and *W*.
- Bruce A. Martin of Brookhaven National LaboratoryBrookhaven National LaboratoryBrookhaven National Laboratory , is a United States national laboratory located in Upton, New York on Long Island, and was formally established in 1947 at the site of Camp Upton, a former U.S. Army base...

considered the choice of A–F "ridiculous" and in a 1968 letter to the editor of the CACMCommunications of the ACMCommunications of the ACM is the flagship monthly journal of the Association for Computing Machinery . First published in 1957, CACM is sent to all ACM members, currently numbering about 80,000. The articles are intended for readers with backgrounds in all areas of computer science and information...

proposed an entirely new set of symbols based on the bit locations, which did not gain much acceptance.
- Soviet programmable calculatorProgrammable calculatorProgrammable calculators are calculators that can automatically carry out a sequence of operations under control of a stored program, much like a computer. The first programmable calculators such as the IBM CPC used punched cards or other media for program storage...

s Б3-34Elektronika B3-34Elektronika B3-34 was a very popular Soviet programmable calculator. It was released in 1980 and was sold for 85 rubles.B3-34 used Reverse Polish notation and had 98 bytes of instruction memory, 4 stack user registers and 14 addressable registers...

and similar used the symbols "−", "L", "C", "Г", "E", " " (space) on their displays.

## Verbal and digital representations

There are no traditional numerals to represent the quantities from ten to fifteen — letters are used as a substitute — and most Western European languages lack non-decimal names for the numerals above ten. Even though English has names for several non-decimal powers (*pair* for the first binaryBinary numeral systemThe binary numeral system, or base-2 number system, represents numeric values using two symbols, 0 and 1. More specifically, the usual base-2 system is a positional notation with a radix of 2...

power, *score20 (number)20 is the natural number following 19 and preceding 21. A group of twenty units may also be referred to as a score.-In mathematics:*20 is the basis for vigesimal number systems....*

for the first vigesimalVigesimalThe vigesimal or base 20 numeral system is based on twenty .- Places :...

power, *dozenDozenA dozen is a grouping of approximately twelve. The dozen may be one of the earliest primitive groupings, perhaps because there are approximately a dozen cycles of the moon or months in a cycle of the sun or year...*

, *grossGross (unit)A gross is equal to a dozen dozen, i.e. 12 × 12 = 144.It can be used in duodecimal counting. The use of gross likely originated from the fact that 144 can be counted on the fingers using the fingertips and first two joints of each finger when marked by the thumb of one hand. The other hand...*

, and *great gross* for the first three duodecimalDuodecimalThe duodecimal system is a positional notation numeral system using twelve as its base. In this system, the number ten may be written as 'A', 'T' or 'X', and the number eleven as 'B' or 'E'...

powers), no English name describes the hexadecimal powers (decimal 16, 256, 4096, 65536, ... ). Some people read hexadecimal numbers digit by digit like a phone number: *4DA* is "four-dee-ay". However, the letter *A* sounds like "eight", *C* sounds like "three", and *D* can easily be mistaken for the "-ty" suffix: Is it *4D* or *forty*? Other people avoid confusion by using the NATO phonetic alphabet: *4DA* is "four-delta-alfa", the Joint Army/Navy Phonetic AlphabetJoint Army/Navy Phonetic AlphabetThe Joint Army/Navy Phonetic Alphabet was a radio alphabet developed in 1941 and was used by all branches of the United States military until the promulgation of the ICAO spelling alphabet in 1956, which replaced it...

("four-dog-able"), or a similar ad hoc system.

Systems of counting on digitsDigit (anatomy)A digit is one of several most distal parts of a limb, such as fingers or toes, present in many vertebrates.- Names:Some languages have different names for hand and foot digits ....

have been devised for both binary and hexadecimal.

Arthur C. ClarkeArthur C. ClarkeSir Arthur Charles Clarke, CBE, FRAS was a British science fiction author, inventor, and futurist, famous for his short stories and novels, among them 2001: A Space Odyssey, and as a host and commentator in the British television series Mysterious World. For many years, Robert A. Heinlein,...

suggested using each finger as an on/off bit, allowing finger counting from zero to 1023 on ten fingers. Another system for counting up to FF (255) is illustrated on the right; it seems to be an extension of an existing system for counting in twelves (dozens and grosses), that is common in South Asia and elsewhere.

## Signs

The hexadecimal system can express negative numbers the same way as in decimal: −2A to represent −42_{10} and so on.

However, some prefer instead to express the exact bit patterns used in the processor and consider hexadecimal values best handled as signed values. This way, the negative number −42_{10} can be written as FFFF FFD6 in a 32-bit CPU registerProcessor registerIn computer architecture, a processor register is a small amount of storage available as part of a CPU or other digital processor. Such registers are addressed by mechanisms other than main memory and can be accessed more quickly...

, as C228 0000 in a 32-bit FPUFloating point unitA floating-point unit is a part of a computer system specially designed to carry out operations on floating point numbers. Typical operations are addition, subtraction, multiplication, division, and square root...

register or C045 0000 0000 0000 in a 64-bit FPU register (assuming certain representation schemes, two's-complement in the 32-bit non-FPU instance and sign-magnitude in the FPU instances.)

## Hexadecimal exponential notation

Just as decimal numbers can be represented in exponential notation so too can hexadecimal. By convention, the letter *p* represents *times two raised to the power of*, whereas *e* serves a similar purpose in decimal. The number after the *p* is **decimal** and represents the **binary** exponent.

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

Example: 1.3DEp42 represents 1.3DE_{16} × 2^{42}.

Hexadecimal exponential notation is required by the IEEE 754 binary floating-point standard. This notation can be produced by some versions of the *printfPrintfPrintf format string refers to a control parameter used by a class of functions typically associated with some types of programming languages. The format string specifies a method for rendering an arbitrary number of varied data type parameter into a string...*

family of functions by using the **%a** conversion.

## Binary conversion

Most computers manipulate binary data, but it is difficult for humans to work with the large number of digits for even a relatively small binary number. Although most humans are familiar with the base 10 system, it is much easier to map binary to hexadecimal than to decimal because each hexadecimal digit maps to a whole number of bits (4_{10}).

This example converts 1111_{2} to base ten. Since each positionPositional notationPositional notation or place-value notation is a method of representing or encoding numbers. Positional notation is distinguished from other notations for its use of the same symbol for the different orders of magnitude...

in a binary numeral can contain either a 1 or a 0, its value may be easily determined by its position from the right:
- 0001
_{2} = 1_{10}
- 0010
_{2} = 2_{10}
- 0100
_{2} = 4_{10}
- 1000
_{2} = 8_{10}

Therefore:
1111_{2}
= 8_{10} + 4_{10} + 2_{10} + 1_{10}
= 15_{10}

With little practice, mapping 1111_{2} to F_{16} in one step becomes easy: see table in Representing hexadecimal. The advantage of using hexadecimal rather than decimal increases rapidly with the size of the number. When the number becomes large, conversion to decimal is very tedious. However, when mapping to hexadecimal, it is trivial to regard the binary string as 4-digit groups and map each to a single hexadecimal digit.

This example shows the conversion of a binary number to decimal, mapping each digit to the decimal value, and adding the results.
01011110101101010010_{2}
= 262144_{10} + 65536_{10} + 32768_{10} + 16384_{10} + 8192_{10} + 2048_{10} + 512_{10} + 256_{10} + 64_{10} + 16_{10} + 2_{10}
= 387922_{10}

Compare this to the conversion to hexadecimal, where each group of four digits can be considered independently, and converted directly:
01011110101101010010_{2}
=
0101_{ }
1110_{ }
1011_{ }
0101_{ }
0010_{2}
=
5
E
B
5
2_{16}
=
5EB52_{16}

The conversion from hexadecimal to binary is equally direct.

The octalOctalThe octal numeral system, or oct for short, is the base-8 number system, and uses the digits 0 to 7. Numerals can be made from binary numerals by grouping consecutive binary digits into groups of three...

system can also be useful as a tool for people who need to deal directly with binary computer data. Octal represents data as three bits per character, rather than four.

### Division-remainder in source base

As with all bases there is a simple algorithmAlgorithmIn mathematics and computer science, an algorithm is an effective method expressed as a finite list of well-defined instructions for calculating a function. Algorithms are used for calculation, data processing, and automated reasoning...

for converting a representation of a number to hexadecimal by doing integer division and remainder operations in the source base. In theory, this is possible from any base, but for most humans only decimal and for most computers only binary (which can be converted by far more efficient methods) can be easily handled with this method.

Let d be the number to represent in hexadecimal, and the series h_{i}h_{i-1}...h_{2}h_{1} be the hexadecimal digits representing the number.

- i := 1
- h
_{i} := d mod 16
- d := (d-h
_{i}) / 16
- If d = 0 (return series h
_{i}) else increment i and go to step 2

"16" may be replaced with any other base that may be desired.

The following is a JavaScriptJavaScriptJavaScript is a prototype-based scripting language that is dynamic, weakly typed and has first-class functions. It is a multi-paradigm language, supporting object-oriented, imperative, and functional programming styles....

implementation of the above algorithm for converting any number to a hexadecimal in String representation. Its purpose is to illustrate the above algorithm. To work with data seriously, however, it is much more advisable to work with bitwise operators.

```
```

```
```

```
```

```
```

```
```