View the Most Wanted LQ Wiki articles.
LinuxQuestions.org > Linux Wiki > Hexadecimal

From LQWiki

(Redirected from Hex)
Jump to: navigation, search

Hexadecimal is a base-16 number system, which means it has 16 digits, starting with zero (0). Thus, 0,1,2,3,4,5,6,7,8,9,A,B,C,D,E,F,10,11,etc., etc.

One hex digit can represent four binary digits, two hex digits can represent eight binary digits (one byte), etc. etc.

MAC and IPv6 addresses are represented in hex.

A hexadecimal number is often represented as a string with '0x' as a prefix, e.g. '0xA' is the decimal number 10.

Contents

Etymology

Coined in the early 1950s to replace earlier sexadecimal, which was too racy and amusing for stuffy IBM, and later adopted by the rest of the industry.

Actually, neither term is etymologically pure. If we take binary to be paradigmatic, the most etymologically correct term for base 10, for example, is `denary', which comes from `deni' (ten at a time, ten each), a Latin distributive number; the corresponding term for base-16 would be something like `sendenary'. "Decimal" comes from the combining root of decem, Latin for 10. If wish to create a truly analogous word for base 16, we should start with sedecim, Latin for 16. Ergo, sedecimal is the word that would have been created by a Latin scholar. The `sexa-' prefix is Latin but incorrect in this context, and `hexa-' is Greek.

Other meanings of Hex

A hex can also be a 6-pack of anything. None of the hacker usages has anything to do with magic or black art, though the pun is appreciated and occasionally used by hackers. True story: As a joke, some hackers once offered some surplus ICs for sale to be worn as protective amulets against hostile magic. The chips were, of course, hex inverters.

C++ Code example to convert between formats

For more C++ code and tips, see C plus plus.

main.cpp

#include <iostream>
using namespace std;

int main()
{
int x;
cout << "Input the number which need be converted:\n";
cin >> x;

cout << uppercase
<< "*octal \t *decimal \t *hexadecimal\n"
<< oct << x << "    \t"
<< dec << x << "       \t\t"
<< hex<< x << endl;
return 0;
}

build and run it:

g++ -o converter main.cpp && ./converter

See also

This article is based, in whole or in part, on entry or entries in the Jargon File.

External links


Personal tools