# HEX

Hexadecimal (abbreviated as hex or subscript 16) is a rounding system in mathematics. It is generally represented by numbers 0 to 9 and letters A to F (or a~f), where: A~F represents 10~15, and these are called hexadecimal numbers.

## Catalogues

### Introduction

A brief overview of hexadecimal is given above. Here is an example:

For example, decimal number 57, 111001 in binary, 39 in hexadecimal. Historically, China has used hexadecimal in the unit of weight, for example, stipulating 16 two as a catty. Today's hexadecimal is generally used in the computer field, because it is not difficult to convert 4 bits into individual hexadecimal digits. 1 byte can be expressed as 2 consecutive hexadecimal digits. However, this mixed representation is easily confusing, so some prefixes, suffixes, or subscripts are required to display.

### Representation

Different computer systems and programming languages have different ways of expressing hexadecimal values:

Ada and VHDL wrap the hexadecimal number with the "digital citation" that they are based on, such as "16#5A3#". (Note: Ada can use any one of 1 to 16 as the base for both integers and real numbers.) For byte vectors, VHDL uses the prefix x to represent, for example, x "10", the corresponding binary code is: "00010000".

C language, C++, Shell, Python, Java and other similar languages use the prefix "0x", for example "0x5A3". The "0" at the beginning makes the parser more recognizable, and the "x" stands for hexadecimal (like "O" for octal). The "x" in "0x" can be uppercase or lowercase. For the amount of characters in C language, it is represented by x + two hexadecimal numbers, such as xFF.

Hexadecimal escape sequence: such as \x1abf4, you can use any number of hexadecimal digits until it is not a hexadecimal digit;

16-bit universal character name (universe-character name): \u must be followed by 4 hexadecimal digits (less than four digits are filled with zeros in front), indicating code points within Unicode 0 to 0xFFFF (but It cannot represent code points within the range of 0xD800 to 0xDFFF. The Unicode standard stipulates that code points within this range are reserved and does not represent characters);

32-bit universal character name: \U must be followed by 8 hexadecimal digits (less than 8 digits are filled with zeros in front), indicating all possible code points in Unicode (except 0xD800 to 0xDFFF).

C++11 introduced hexadecimal floating-point literal constants. For example: 0x1.2p10 means (1+2/16)×2=115210. In fact, the C/C++ standard library function printf that Visual C++ has always used, %a as the type specifier to format the output floating-point value is the above format.

When C/C++ represents a character literal constant, you can use:

In VB, MSX BASIC, Quick BASIC and FreeBASIC, the prefix "&H" is used.

In HTML, "x" can be used for hexadecimal characters, and the effect should be the same.

In Intel's assembly language, the suffix "h" is used to identify the hexadecimal number (if the number starts with a letter, a "0" will be added in front). For example, "0A3Ch", "5A3h"

Other assemblers (Motorola, 6502), Pascal, Delphi and some BASIC versions use prefixes,

X'5A3' is also useful, as in PL/I, COBOL and JCL. This is also the most commonly used data format on IBM mainframes and minicomputers with early operating systems.

Since there is no single, agreed standard for presentation, the above presentations are used, and sometimes several different presentations will appear on the same paper. But because there is not much difference between the various methods, so even if they are mixed, there is no problem.

The most common (or common) way of representing hexadecimal values is to add '0x' in front of the number, or add the small letter 16 after the number. For example, 0x2BAD and 2BAD16 both represent 11181 (or 1118110) in decimal.

Hexadecimal is very commonly used in web design. HTML and CSS use hexadecimal notation to represent specific colors on web pages. Use the # symbol to represent hexadecimal rather than individual symbols. 24-bit color can be expressed in the format #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. For example, the shade of red is decimal 238,9,63 can be programmed as #EE093F.

Mathematical calculation method

Main article: Hex conversion

Use the remainder theorem to decompose, for example, convert 487710 to hexadecimal:

4877÷16=304...13(D)

304÷16=19....0

19÷16=1...3

1÷16=0....1

In this way, 487710=130D16

Functions in programming

Visual Basic

Convert hexadecimal to decimal: Decimal (Long type) = CLng ("&H" & hexadecimal number (String type))

Javascript

Javascript can use the toString() function to convert decimal numbers to other arbitrary format (String type)

Python

Call Python's built-in int() function to convert the string to a number.

Need Help?

Support