hexadecimal

A counting method
open 2 entries with the same name
Collection
zero Useful+1
zero
synonym Hexadecimal number (Representation method of data in computer) Generally refers to hexadecimal (a counting method)
hexadecimal (abbreviated as hex Or subscript 16) is a counting system with a radix of 16 Carry system It is usually represented by the numbers 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 and the letters A, B, C, D, E, F (a, b, c, d, e, f), where A~F represents 10~15, which are called Hexadecimal digit
Chinese name
hexadecimal
Foreign name
Hexadecimal
Definition
computer A Representation Method of Data in
Cardinal number
sixteen
Digital
0, 1, 2, 3, 4, 5, 6, 7, 8, 9 and the letters A, B, C, D, E, F (a b、c、d、e、f)

brief introduction

Announce
edit
The above hexadecimal A brief overview is given. Here is an example:
for example decimal system Number 57, at Binary Write 111001, and write 39 in hexadecimal system. Nowadays, hexadecimal is widely used in computer This is because it is not too difficult to convert 4 bits into separate hexadecimal digits. One byte can be represented as two consecutive hexadecimal digits. However, this mixed representation is easy to confuse, so it needs some prefixes, suffixes or subscripts to display. [1]

Representation

Announce
edit
Different computer system programing language There are different representations for hexadecimal values:
  • Ada And VHDL Wrap the hexadecimal number with the "number citation" based on, such as "16 # 5A3 #". (Note: Ada can use either integer or real number from 1 to 16 as its radix.) For byte vectors, VHDL Use the prefix x, for example, x "10", and the corresponding binary code is "00010000".
  • C language C++ Shell Python Java Language and other similar languages use the prefix "0x", such as "0x5A3". "0" order at the beginning Parser More recognizable number, while "x" stands for hexadecimal (just as "O" stands for octal number system )。 The "x" in "0x" can Uppercase or a lowercase letter The character quantity in C language is represented by x+two hexadecimal digits, such as xFF.
  • Hexadecimal escape sequence: for example, x1abf4, you can use any number of hexadecimal digits until they are not hexadecimal digits;
  • 16 bit universal character name: u must be followed by four hexadecimal digits (less than four digits must be supplemented with zeros), representing code points in Unicode within the range of 0 to 0xFFFF (but not code points within the range of 0xD800 to 0xDFFF. Unicode standards stipulate that code points within this range are reserved and do not represent characters);
  • 32-bit universal character name: U must be followed by 8 hexadecimal digits (less than eight digits must be preceded by zeros), representing all possible code points in Unicode (except 0xD800 to 0xDFFF).
  • C++11 introduces hexadecimal float Literal constant For example, 0x1.2p10 means (1+2/16) × 2=1152 ten In fact, the C/C++language standard library function printf,% a used by Visual C++as a type specifier to format the output floating point value is the above format. For example: printf ("% a", 1152.0);
  • stay VB 、MSX BASIC、 Quick BASIC and FreeBASIC In, use the prefix "&H" to indicate.
  • stay HTML , hexadecimal characters can use "x", for example&# x5a3; The effect should be the same as that of Guangzhou.
  • Intel's assembly language The suffix "h" is used to identify 16 carry numbers (if the number starts with a letter, a "0" will be added in front), such as "0A3Ch", "5A3h"
  • other Assembler AT&T Motorola 、6502), Pascal Delphi And some BASIC versions use the prefix "$", such as "$5A3"
  • It can also be used in the form of X '5A3', such as PL/I COBOL and JCL Medium. This is also IBM Mounting of earlier operating systems mainframe And Minicomputer The most commonly used data format on.
  • Since there is no single, agreed standard for representation, all of the above representations have been used, and sometimes even several different representations appear in the same paper. However, because there is not much difference between the various methods, even mixed use does not pose a problem.
  • The most common (or common) way to represent hexadecimal values is to add '0x' before the number, or add 16 small words after the number. For example 0x2BAD and 2BAD sixteen It means decimal system 11181 (or 11181 ten )。
  • stay Web Design Upper hexadecimal is very common. HTML and CSS Use hexadecimal notation to represent specific colors on a Web page. Use the symbol of # to represent hexadecimal instead of individual symbols. The 24 bit color can be expressed in the format of # RRGGBB. RR is the value of the red component in the color, GG is the value of the green component in the color, and BB is the value of the blue component in the color. For example, the red shadow is decimal 238,9,63, which can be coded as # EE093F. [1]

Representation method table

Here hex is carried into the specific hexadecimal number
Environmental Science
format
remarks
URL
%hex
XML,XHTML
&#xhex
HTML,CSS
#hex
6 bits for color
Unicode
U+hex
6 bits, representing character code
MIME
=hex
Modula-2
#hex
Smalltalk,ALGOL 68
16rhex
Common Lisp
#Xhex or # 16rhex
IPv6
8 hexes are separated by:

Hexadecimal conversion

Announce
edit

computing method

Main entry: decimal conversion
Decimal to hexadecimal
Mining Remainder theorem Disassemble, such as 4877 ten Convert to hexadecimal:
4877÷16=304....13(D)
304÷16=19....0
19÷16=1....3
1÷16=0....1
This counts to 4877 ten =130D sixteen

Programming function

    • Conversion from hexadecimal to decimal: decimal (Long type)=CLng ("&H"&hexadecimal number (String type))
    • Conversion from decimal to hexadecimal: hexadecimal number (String type)=Hex $(decimal)
  • Javascript can use the toString() function to convert decimal numbers to other arbitrary decimal formats (String type)
  • Call the Python built-in int () function to convert the string to a number. [2]