Information AboutHexadecimal |
| CATEGORIES ABOUT HEXADECIMAL | |
| computer arithmetic | |
| positional numeral systems | |
| 16 | |
|
In Mathematics and Computer Science , hexadecimal, '' Base -'', or simply '''hex''', is a Numeral System with a Radix , or base, of 16, usually written using the symbols 0–9 and A–F, or a–f. Its primary purpose is to represent the Binary Code in a format easier for humans to read, and acts as a form of Shorthand , in which one hexadecimal digit stands in place of four binary Bit s. For example, the Decimal numeral 79, whose Binary representation is 01001111, is 4F in hexadecimal (4 = 0100, F = 1111). IBM introduced the current hexadecimal system to the computing world; an earlier version, using the digits 0–9 and u–z, had been introduced in 1956, and had been used by the Bendix G-15 computer. USES Hexadecimal is primarily used in computing to represent a Byte . Representing the 256 possible values has a number of problems: first, there are unprintable control characters; second, ASCII itself stops at 7 bits with the remainder being system-specific extensions; and finally, even if all characters in the machine's set were displayable as something, neither users nor input methods are generally prepared to handle 256 unique characters. Hex triplets . Example of conversion from hexadecimal triplet to decimal triplet: Hexadecimal triplet: FFCF4B Step 1: Separate the triplets: FF CF 4B Step 2: Convert each hexadecimal value to a decimal representation:
Result: Hexadecimal triplet FFCF4B = Decimal triplet 255,207,75 Other common uses In character code for a space (" ") is 20. Some Software programs will create unique order numbers by using a hexadecimal representation of the exact second the order was taken, based on the total number of seconds since the start of the 20th Century . For example, C9BCE0F5 represents ''April 2, 2007 14:19:32''. Page numbers on Teletext are written in hexadecimal, with available numbers being in the range of 100-8FF. However, page numbers with letters are only used for "hidden" and engineering pages. REPRESENTING HEXADECIMAL Some hexadecimal representations are indistinguishable from decimal representations (to humans and computers); therefore, some convention is usually used to flag them. In typeset text, hexadecimal is often indicated by a subscripted suffix such as 5A316, 5A3SIXTEEN, or 5A3HEX. In computer programming languages, alternatively which are nearly always Plain Text without such typographical distinctions as subscript and superscript—,a wide variety of ways indicate hexadecimal representations; these are even seen in typeset text, especially in text that relates to a programming language. The following are some of the most common representations:
]] There is no single agreed-upon standard, so all the above conventions are in use, sometimes even in the same paper. However, as they are quite unambiguous, little difficulty arises from this. The most commonly used (or encountered) notations are the ones with a prefix "0x" or a subscript-base 16, for hex numbers. For example, both 0x2BAD and 2BAD16 represent the Decimal number 11181 (or 1118110). The choice of the letters ''A'' through ''F'' to represent the additional digits was not universal in the early history of computers. During the 1950s, some installations favored using the digits 0 through 5 with a Macron to indicate the values 10-15. Users of Bendix G-15 computers used the letters ''U'' through ''Z''. One solution how to write hexadecimal numbers distinctively is the use of figures that are made for the hexadecimal system but are not yet representable in Unicode . VERBAL REPRESENTATIONS Not only are there currently no proper digits to represent the quantities from ten to fifteen (so letters are used as a substitute), but English also lacks a proper nomenclature to name hexadecimal numbers. Names such as "thirteen" and "fourteen" are Decimal -based, and even though English has a few names for non-decimal powers —'' Pair '' for the first Binary power; '' Score '' for the first Vigesimal power; '' Dozen '', '' Gross '' and '' Great Gross '' for the first three Duodecimal powers—, no English name currently exists for any of the hexadecimal powers (corresponding to the decimal values 16, 256, 4096, 65 536, 1 048 576, 16 777 216, etc.). So people have resorted to reading hexadecimal numbers by naming their digits (or digit-letters) individually in sequence in the same way as reading phone numbers (i.e., 4DA as "four-dee-aye"). However, the letter 'A' sounds similar to '8', 'C' sounds similar to '3', and 'D' can easily be mistaken for the 'ty' suffix as in "forty"; so 4DA could be mistaken for 48. To avoid misunderstandings, some convention must be established when exchanging hexadecimal numbers verbally, at least until a proper hexadecimal nomenclature is developed (if ever). To avoid confusion, the digits A-F are commonly pronounced with the NATO Phonetic Alphabet ("four-delta-alpha"), the World War II era Joint Army/Navy Phonetic Alphabet ("four-dog-able"), or some approximation of one of those systems. FRACTIONS As with other numeral systems, the hexadecimal system can be used to represent Rational Number s, although Recurring Digits are common since 16 has only a single prime factor: Because the radix 16 is a Perfect Square (42), fractions expressed in hexadecimal have an odd period much more often than decimal ones, and there are no Cyclic Number s (other than trivial single digits). Recurring digits occur when the denominator in lowest terms has a Prime Factor not found in the radix; thus, when using hexadecimal notation all fractions with denominators that are not a Power Of Two will result in an infinite string of recurring digits (e.g., thirds and fifths). This makes hexadecimal (and binary) less convenient than Decimal (not to mention Duodecimal and Sexagesimal ) for the purpose of representing rational numbers, since a larger proportion of them lie outside its range of finite representation. All rational numbers finitely representable in hexadecimal are also finitely representable in decimal, duodecimal and sexagesimal (i.e., any hexadecimal number with a finite number of digits will have a finite number of digits when expressed in those other bases), whereas only a fraction of those finitely representable in the latter ones are finitely representable in the former (e.g., decimal 0.1, that is, the fraction one tenth, corresponds to the infinite recurring representation 0.199999999999... in hexadecimal). Although hexadecimal is more efficient than those other bases for the particular case of representing fractions with powers of two as the denominator (cf. one sixteenth is 0.1 in hexadecimal, 0.09 in duodecimal, 0;3,45 in sexagesimal and 0.0625 in decimal). MAPPING TO BINARY Sometimes it is necessary to use binary data when working with computers, but it is difficult for humans to work with the large number of digits in binary. Although most humans are more 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 (410). The following is an example of converting 11112 to base 10. Since each Position in a binary numeral can only contain either a 1 or 0, its value may be easily determined by its position from the right:
Therefore:
This example shows addition of 4 numbers; but with some practice, 11112 can be mapped directly to F16 in one step (see table in Representing Hexadecimal ). The advantage of using hexadecimal rather than decimal increases with the size of the number. When the number becomes large, conversion to decimal becomes much more tedious; however, when mapping to hexadecimal, it is simple to divide the binary string into blocks of 4 positions and map each block of 4 bits to a single position hexadecimal digit. This example shows the conversion of a binary number to decimal, mapping each digit to the decimal value, and adding the results.
Compare this to the conversion to hexadecimal, where each group of four digits can be considered independently, and converted directly:
Conversion from hexadecimal back to binary is just as direct. The Octal system can also be useful as a tool for people who need to deal directly with binary computer data, as in reading and understanding it. Compared to hexadecimal, octal represents data in blocks of 3 bits each, rather than 4. One advantage of hexadecimal is that every unique 2-digit pair (or octet) always represents the same byte value. To "translate" a hexadecimal value into bytes, one needs only to separate the value into individual 2-digit groups, translate each group into its respective byte value, and then combine the results together to form an accurate translation of the entire original hexadecimal word. Conversely, bytes can also be easily translated into hexadecimal values by translating each byte individually into its hexadecimal 2-digit value, and then recombining the hexadecimal values into a "word". The resulting "word" will be an accurate hexadecimal representation of the original string of bytes. CONVERTING FROM OTHER BASES Division-remainder in source base As with all bases there is a simple Algorithm for converting a representation of a number to hexadecimal by doing integer division and remainder operations in the source base. Theoretically 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 hihi-1...h2h1 be the hexadecimal digits representing the number. #i := 1 #hi := d mod 16 #d := (d-hi) / 16 #If d = 0 (return series hi) else increment i and go to step 2 "16" may be replaced with any other base that may be desired. The following is a JavaScript 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 . function toHex(d) {Addition and multiplication in hexadecimal 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. Conversion via binary As computers generally work in binary the normal way for a computer to make such a conversion would be to convert to binary first (by doing multiplication and addition in binary) and then make use of the direct mapping from binary to hexadecimal. ETYMOLOGY It was IBM that decided on the prefix of "hexa" rather than the proper Latin prefix of "sexa". The word "hexadecimal" is strange in that ''hexa'' is derived from the proper Greek term would be ''hexadecadic'' (although in Modern Greek ''deca-hexadic (δεκαεξαδικός)'' is more commonly used). HUMOR Hexadecimal is sometimes used in programmer jokes because certain words can be formed using only hexadecimal digits. Some of these words are "dead", "beef", "babe", and with appropriate substitutions "c0ffee". Since these are quickly recognisable by programmers, debugging setups sometimes initialize memory to them to help programmers see when something has not been initialized. Some people add an H after a number if they want to show that it is written in hexadecimal. In older Intel Assembly syntax, this is sometimes the case. This may be the forerunner of the modern web parlance of " 1337speak " An example is the Magic Number in FAT Mach-O files and Java programs, which is " CAFEBABE". Single-architecture Mach-O files have the magic number "FEEDFACE" at their beginning.A Knuth Reward Check is one hexadecimal dollar, or $2.56. The following table shows a joke in hexadecimal: 3x12=36 2x12=24 1x12=12 0x12=18 The first three are multiples of 12, while in the last one "0x12" in hex is 18. 0xdeadbeef is sometimes put into uninitialized memory. Microsoft Windows XP clears its locked index.dat files with the hex codes: "0BADF00D" TRIVIA
SEE ALSO
REFERENCES EXTERNAL LINKS
|
|
|