English Deutsch Français Italiano Español Português 繁體中文 Bahasa Indonesia Tiếng Việt ภาษาไทย
All categories

2006-09-19 07:55:06 · 0 answers · asked by anks.sinha 1 in Education & Reference Other - Education

0 answers

Get the last digit of the hex number, call this digit the currentDigit.
Make a variable, let's call it power. Set the value to 0.
Multiply the current digit with (16^power), store the result.
Increment power by 1.
Set the the currentDigit to the previous digit of the hex number.
Repeat from step 3 until all digits have been multiplied.
Sum the result of step 3 to get the answer number.
Example 1
Convert the number 1128 HEXADECIMAL to DECIMAL

MULTIPLICATION RESULT NOTES
8 x (16^0) 8 Start from the last digit of the number. In this case, the number is 1128. The last digit of that number is 8. Note that the power of 0 of any number is always 1

2 x (16^1) 32 Process the previous, which is 2. Multiply that number with an increasing power of 16.
1 x (16^2) 256 Process the previous digit, which is 1, note that 16^2 means 16 x 16
1 x (16^3) 4096 Process the previous digit, which is 1, note that 16^3 means 16 x 16 x 16
Here, we stop because there's no more digit to process
ANSWER 4392 This number comes from the sum of the RESULTS
(8+32+256+4096)=4392

Once discerned, notice that the above process is essentially performing this calculation:

1x(16^3) + 1x(16^2) + 2x(16^1) + 8x(16^0)

When doing this by hand, it is easier to start backward is because:

Counting the number of digits takes extra time, and you might count wrongly.
If you don't remember what a particular value of a power-of-16 is, it's easier to calculate it from the previous power value. For instance, if you don't remember what the value of 16^3 is, then just multiply the value of 16^2 (which you'll likely already have if you started backward) with 16.
Example 2
Convert the number 589 HEXADECIMAL to DECIMAL

MULTIPLICATION RESULT
9 x (16^0) 9
8 x (16^1) 128
5 x (16^2) 1280

ANSWER 1417

If you want to be a speed counter, it's beneficial to memorize the values of the smaller power of 16s, such as in this table

POWER OF 16s RESULT
16^0 1
16^1 = 16 16
16^2 = 16x16 256
16^3 = 16x16x16 4096
16^4 = 16x16x16x16 65536

Example 3
Convert the number 1531 HEXADECIMAL to DECIMAL
(This time, let's use the table of the power-of-16s above.)

MULTIPLICATION RESULT
1 x 1 1
3 x 16 48
5 x 256 1280
1 x 4096 4096

ANSWER 5425

Example 4
Convert the number FA8 HEXADECIMAL to HEXADECIMAL

MULTIPLICATION RESULT
8 x 1 8
A x 16 (remember that hex A=decimal 10) 160
F x 256 (remember that hex F=decimal 15) 3840

ANSWER 4008

Example 5
Convert the number 8F HEXADECIMAL to DECIMAL

DIVISION RESULT
F x 1 15
8 x 16 128

ANSWER 143

Example 6
Convert the number A0 HEXADECIMAL to DECIMAL

DIVISION RESULT
0 x 1 0
A x 16 160

ANSWER 160

Example 7
Convert the number 12 HEXADECIMAL to DECIMAL

DIVISION RESULT
2 x 1 2
1 x 16 16

ANSWER 18

Example 8
Convert the number 35432 HEXADECIMAL to DECIMAL

2x(16^0) + 3x(16^1) + 4x(16^2) + 5x(16^3) + 3x(16^4) =
2 + 3x16 + 4*256 + 5*4096 + 3*65536 =
2 + 48 + 1024 + 20480 + 196608 =
218162
EXAMPLE CONVERSION - HEX TO DECIMAL

Hex Decimal Equivalent
9AC3 39,619


Hex=Decimal Comment Hexadecimal number to be converted Decimal Equivalent
0=0
1=1
2=2
3=3
4=4
5=5
6=6
7=7
8=8
9=9
A=10
B=11
C=12
D=13
E=14
F=15 Columns are numbered from right to left, starting at column zero, not column one column 3 column 2 column 1 column 0
Write the hex number with one digit per column 9 A C 3
Convert the hex digit to decimal 9 10 12 3
Multiply each digit by 16 to the power of n, where n is the column number 9 x (16^3) 10 x (16^2) 12 x (16^1) 3 x (16^0)
Put the answer in this row, and add all the answers together 36,864 + 2,560 + 192 + 3 = 39,619

Definitions:
16^3 = 16 to the power of 3 = (16 x 16 x 16) = 4,096
16^0 = 16 to the power of 0 = 1 (anything to the power of zero equals one.)

Explanation:
Each hex digit is multiplied by 16^n, where n is its column number, numbering from right to left, starting at column zero (not column 1).
Then all the answers are added together. This gives you the decimal equivalent of the hex number you started with.

A general formula can be derived for those familiar with mathematical notation:
Decimal Equiavalent = Σ (Hn x 16^n) from n = 0 to n
where Σ means "sum", n is the column number, and Hn is the hex digit in the n-th column


--------------------------------------------------------------------------------


EXAMPLE CONVERSION - HEX TO BINARY


Hex Binary Equivalent
9AC3 1001 1010 1100 0011


Hex=Binary Comment Hexadecimal number to be converted Binary Equivalent
0=0000
1=0001
2=0010
3=0011
4=0100
5=0101
6=0110
7=0111
8=1000
9=1001
A=1010
B=1011
C=1100
D=1101
E=1110
F=1111 Hex is directly related to binary and the order of conversion does not matter. You can start at column 3 or column zero. column 3 column 2 column 1 column 0
Write the hex number with one digit per column 9 A C 3
Convert each hex number directly into binary 1001 1010 1100 0011
The usual use of binary is in computers where the binary digits are called bits and are grouped by 8's to make one byte (one byte = 8 bits) 1001 1010 1100 0011 1001 1010 1100 0011
In mathematics and computer science, base-16, hexadecimal, 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. For example, the decimal numeral 79 whose binary representation is 01001111 can be written as 4F in hexadecimal (4 = 0100, F = 1111). The current hexadecimal system was first introduced to the computing world in 1963 by IBM. An earlier version, using the digits 0–9 and u–z, was used by the Bendix G-15 computer, introduced in 1956.

Contents [hide]
1 Representing hexadecimal
2 Uses
3 Fractions
4 Etymology
5 Humor
6 Mapping to binary
7 Converting from other bases
7.1 Division-remainder in source base
7.2 Addition and multiplication in hexadecimal
7.3 Conversion via binary
8 Cultural References
9 See also
10 References
11 External links



[edit]
Representing hexadecimal
Hex Bin Dec
0 0000 0
1 0001 1
2 0010 2
3 0011 3
4 0100 4
5 0101 5
6 0110 6
7 0111 7
8 1000 8
9 1001 9
A 1010 10
B 1011 11
C 1100 12
D 1101 13
E 1110 14
F 1111 15
Some hexadecimal numbers are indistinguishable from a decimal number (to both humans and computers). Therefore, some convention is usually used to flag them.

In typeset text, the indication is often a subscripted suffix such as 5A316, 5A3SIXTEEN, or 5A3HEX.

In computer programming languages (which are nearly always plain text without such typographical distinctions as subscript and superscript) a wide variety of ways of marking hexadecimal numbers have appeared. These are also seen even in typeset text especially if that text relates to a programming language.

Some of the more common textual representations:

Ada and VHDL enclose hexadecimal numerals in based "numeric quotes", e.g. "16#5A3#". (Note: Ada accepts this notation for all bases from 2 through 16 and for both integer and real types.)
C and languages with a similar syntax (such as C++, C#, Java and Javascript) prefix hexadecimal numerals with "0x", e.g. "0x5A3". The leading "0" is used so that the parser can simply recognize a number, and the "x" stands for hexadecimal (cf. 0 for Octal). The "x" in "0x" can be either in upper or lower case but is almost always seen written in lower case.
*nix shells use an escape character form "\x0FF" in expressions and "0xFF" for constants.
In HTML, hexadecimal character references also use the x: ֣ should give the same as ֣ – with your browser ֣ and ֣ respectively (Hebrew accent munah). Hexadecimal color references are prefixed with "#", e.g. "#FFFFFF" (white).
Some assemblers indicate hex by an appended "h" (if the numeral starts with a letter, then also with a preceding 0, to indicate that it is a number), e.g., "0A3Ch", "5A3h".
Postscript indicates hex by a prefix "16#".
Common Lisp use the prefixes "#x" and "#16r".
Pascal, other assemblers (AT&T, Motorola), and some versions of BASIC use a prefixed "$", e.g. "$5A3".
The Smalltalk programming language uses the prefix "16r". Note Smalltalk accepts the format "r" where radix is a number base from 2 upwards (i.e. 2r1110 is 10r14 or 16rE), with the practical limitation being within the ASCII character set range 0-9 and A-Z used to represent the digits. Some versions of Smalltalk allow fractional digits following a period character, ".", enabling hexadecimal (and other bases of) floating point numbers to be represented.
Some versions of BASIC, notably Microsoft's variants including QBasic and Visual Basic), prefix hexadecimal numerals with "&H", e.g. "&H5A3"; others such as BBC BASIC just used "&" (used for octal in Microsoft's BASIC!).
TI 89 and 92 series designate 0h (ex 0hA3)
Notations such as X'5A3' are sometimes seen; PL/I uses such notation.
Donald Knuth introduced the use of different fonts to represent radices in his book The TeXbook. In his notation, hexadecimal numbers are represented in a typewriter type, e.g. 5A3

A hexadecimal multiplication tableThere 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 computers used the letters U through Z.

[edit]
Uses
A common use of hexadecimal numerals is found in HTML and CSS. They use hexadecimal notation (hex triplets) to specify colours on web pages; there is just the # symbol, not a separate symbol for "hexadecimal". Twenty-four-bit color is represented in the format #RRGGBB, where RR specifies the value of the Red component of the color, GG the Green component and BB the Blue component. For example, a shade of red that is (238,9,63) in decimal is coded as #EE093F. This syntax is borrowed from the X Window System.

Example of conversion from hexadecimal triplet to decimal triplet: Hexadecimal triplet: FFCF4B

Separate the triplets: FF CF 4B

Convert each hexadecimal value to a decimal number:

FF = 15*16 + 15*1 = 255
CF = 12*16 + 15*1 = 207
4B = 4*16 + 11*1 = 75
Hexadecimal triplet FFCF4B = Decimal triplet 255,207,75

Hexadecimal is used also in more generic computing, as the most commonly found form of expressing a guaranteeably human-readable string representation of a byte. All the possible values of a byte (256 values) can be represented by a 2 digit hexadecimal number. Some people assume that using 8-bit "ASCII" to represent the value of a byte should work, but this has a number of problems, firstly there are a number of unprintable control characters, secondly ASCII itself stops at 7 bits with the remainder being system specific extentions and finally even assuming all characters in the machines set were displayable as something neither users nor input methods are generally prepared to handle 256 unique characters.

In URLs, all characters can be coded hexadecimally, even those not normally permitted. Each 2-digit (1 byte) hexadecimal number is preceded by a percent sign and refers to a specific ASCII character code. For example, in the URL [1], the ASCII character code for a space (" ") is 20.

The canonical written form of numeric IPv6 addresses represents each group of 16 bits as a separate hexadecimal number, to ease reading and transcription of the 128-bit addresses.

Page numbers on teletext are hexadecimal, with available numbers being in the range of 100-8FF. However, page numbers with letters are only used for "hidden" and engineering pages.

In October 1996, Simon Plouffe, Peter Borwein and Jonathan Borwein created an equation that allows the nth digit of pi in hexadecimal to be calculated, without knowing all (or indeed any) of the previous digits. The equation is given by:

[edit]
Fractions
As with other numeral systems, the hexadecimal system can be used in forming vulgar fractions, although recurring digits are common since 16 has only a single prime factor:


1/ 0x1 = 0x1 1/ 0x5 = 0x0.3 1/ 0x9 = 0x0.1C7 1/ 0xD = 0x0.13B
1/ 0x2 = 0x0.8 1/ 0x6 = 0x0.2A 1/ 0xA = 0x0.19 1/ 0xE = 0x0.1249
1/ 0x3 = 0x0.5 1/ 0x7 = 0x0.249 1/ 0xB = 0x0.1745D 1/ 0xF = 0x0.1
1/ 0x4 = 0x0.4 1/ 0x8 = 0x0.2 1/ 0xC = 0x0.15 1/ 0x10 = 0x0.1

Because the radix 16 is a square (42), hexadecimal fractions have an odd period much more often than decimal ones. Recurring decimals occur when the denominator in lowest terms has a prime factor not found in the radix. In the case of hexadecimal numbers, all fractions with denominators that are not a power of two will result in a recurring decimal.

[edit]
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 Greek έξ (hex) for "six" and decimal is derived from the Latin for "tenth". It may have been derived from the Latin root, but Greek deka is so similar to the Latin decem that some would not consider this nomenclature inconsistent. An older term was the incorrect Latin-like "sexidecimal" (correct Latin is "sedecim" for 16), but that was changed because some people thought it too risqué, and it also had an alternative meaning of "base 60". However, the word "sexagesimal" (base 60) retains the prefix. The earlier Bendix documentation used the term "sexadecimal". Donald Knuth has pointed out that the etymologically correct term is "senidenary", from the Latin term for "grouped by 16". (The terms "binary", "ternary" and "quaternary" are from the same Latin construction, and the etymologically correct term for "decimal" arithmetic should be "denary".)[1] Schwartzman notes that the expected purely Latin form would be "sexadecimal", but then computer hackers would be tempted to shorten the word to "sex".[2] Incidentally, the etymologically proper Greek term would be hexadecadic.

[edit]
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". This is an example of such a joke. Since these are quickly recognisable by programmers, debugging setups sometimes initialise memory to them to help programmers see when something has not been initialised. Some people add an H after a number if they want to show that it is a hexadecimal number. In older intel assembly syntax, this is sometimes the case. With that last H it becomes possible to write new words and sentences, such as for example 1517ADEADB17CH (is it a dead *****).

This may be the forrunner of the modern web parlance of "1337speak"

Another example is the magic number in FAT Mach-O files and java programs, which is "CAFEBABE".

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"

[edit]
Mapping to binary
When working with computers we often need to deal with binary data. It is much easier for humans to handle numbers in hexadecimal than in binary (since binary values must be written with more digits than their decimal and hexadecimal counterparts, just think of lots of '0's and '1's) and whilst we are more familiar with the base 10 system, it is much easier to map binary to hexadecimal than to decimal since each hexadecimal digit maps to a whole number of bits (410).

Consider converting 11112 to base 10. Since each position in a binary (base 2) number can only be either a 1 or 0, its value may be easily determined by its position from the right:

00012 = 110
00102 = 210
01002 = 410
10002 = 810
Therefore:

11112 = 810 + 410 + 210 + 110
= 1510

This is a very simple example which still requires the addition of 4 numbers; whereas, with some practice, 11112 can be mapped directly to F16 in one step (see table in Representing hexadecimal). When the binary number is very much greater, conversion to decimal becomes much more tedious; however, when mapping to hexadecimal, it is simple to divide the binary number up in blocks of 4 positions and map each block of 4 bits to a single position hexadecimal number. For example a tedious conversion to decimal:

010111101011010100102 = 26214410 + 6553610 + 3276810 + 1638410 + 819210 + 204810 + 51210 + 25610 + 6410 + 1610 + 210
= 38792210

Compared to the conversion to hexadecimal:

010111101011010100102 = 0101 1110 1011 0101 00102
= 5 E B 5 216
= 5EB5216

Conversion from hexadecimal back to binary is just as direct.

Octal is also useful as a way for humans to deal with computer data (in blocks of 3 bits instead of 4); however, hexadecimal's big advantage over octal is that exactly 2 digits represent a byte (octet). This means that with hexadecimal, you can easily see from the value of a word what the value of the individual bytes will be; conversely, if you have the values of the bytes, you can easily assemble them to get the value of a word.

[edit]
Converting from other bases
[edit]
Division-remainder in source base
As with all bases there is a simple algorithm for converting 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 decimal number to convert, and the series hihi-1...h2h1 be the hexadecimal digits representing the number.

1. H1 := d mod 16
2. D := (d-h1) / 16
3. If d==0 (return series hi)
else go to 1

"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 (maybe other uses that may be thought of). To work with data seriously however, it is much more advisable to work with bitwise operators.

function toHex(d) {
var r = d % 16;
if(d-r==0) {return toChar(r);}
else {return toHex( (d-r)/16 )+toChar(r);}
}

function toChar(n) {
var alpha = "0123456789ABCDEF";
return alpha.charAt(n);
}
[edit]
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 full hexadecimal number.

[edit]
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 and then make use of the direct mapping from binary to hexadecimal.

[edit]
Cultural References
In The Simpsons, on the episode Treehouse of Horror VI, where Homer enters the third dimension (Homer³), a hexadecimal string (46 72 69 6e 6b 20 52 75 6c 65 73 21) is floating in "3-D land" which, when used as character indices in the ASCII character set, translates to "Frink rules!" (excluding the quotes but including the exclamation mark).

In the TV show ReBoot there is a villainous character named Hexadecimal, who appears as a harlequin with constantly-changing masks, each with a different facial expression to represent differing emotional states.

In 1998, Subaru sold a special edition Impreza called the WRX-STi 22B. While some contend the name was derived from the use of a 2.2L motor ("22") and Bilstein brand ("B") suspension components, it has also been shown that "22B" is the hexadecimal equivalent of "555," where State Express 555 is the British American Tobacco brand that sponsored Subaru's early rally efforts.

[edit]
See also
Base32
Base64
Bubble Babble
Hex editor
Hexadecimal time
Hexspeak
Nibble — one hexadecimal digit can exactly represent one "nibble"
Numeral system — a list of other base systems
Binary numeral system
HTML
[edit]
References
^ Knuth, Donald. (1969). Donald Knuth, in The Art of Computer Programming, Volume 2. ISBN 0-201-03802-1. (Chapter 17.)
^ Schwartzman, S. (1994). The Words of Mathematics: an etymological dictionary of mathematical terms used in English. ISBN 0-88385-511-9.
Just like the octal number system, the hexadecimal (or base-sixteen) number system provides a convenient way to express binary numbers. Table 2-6 shows the weighting for the hexadecimal number system up to 3 decimal places before and 2 places after the hexadecimal point. Based on the trend in previous number systems, the methods used to convert hexadecimal to decimal and vice versa should be intuitive



Weights
162
161
160
.
16-1
16-2


Table 2-6 Hexadecimal Weights

Table 2-7 lists the equivalent decimal, binary and hexadecimal representations for the decimal numbers ranging from 0 to 15.



Decimal
Binary
Hexadecimal

0
0000
0

1
0001
1

2
0010
2

3
0011
3

4
0100
4

5
0101
5

6
0110
6

7
0111
7

8
1000
8

9
1001
9

10
1010
A

11
1011
B

12
1100
C

13
1101
D

14
1110
E

15
1111
F


Table 2-7 Number Systems Equivalency Table

Note that each hexadecimal number may be represented as a 4 digit binary number.



Converting Hexadecimal to Binary
Because each hexadecimal digit can be represented by a four-bit binary number (see Table 2-7), it is very easy to convert from hexadecimal to binary. Simply replace each hexadecimal digit with the appropriate four-bit binary number as indicated in the examples below.

Examples

A3 16 = (10100011) 2

(37.12) 16 = (00110111.00010010) 2







Converting Binary to Hexadecimal
Converting binary to hexadecimal is another simple process. Break the binary digits into groups of four starting from the binary point and convert each group into its appropriate hexadecimal digit. For whole numbers, it may be necessary to add a zero as the MSB in order to complete a grouping of four bits. Note that this addition does not change the value of the binary number. Similarly, when representing fractions, it may be necessary to add a trailing zero in the LSB in order to form a complete grouping of four.



Examples:

Converting (1010111) 2 to hexadecimal

0111 = 7 (LSB)

0010 = 5 (MSB)

thus (1010111) 2 = (57) 16



Converting (0.00111111) 2 to hexadecimal

0011 = 3 (MSB)

1111 = F (LSB)

thus (0.00111111) 2 = (0.3F) 16

2006-09-19 08:02:29 · answer #1 · answered by neema s 5 · 0 0

BAD = 189
DEAF = 57007
FEEB = 65259
and...
F0AD = 61613 ;)

2006-09-19 08:02:22 · answer #2 · answered by John's Secret Identity™ 6 · 0 0

fedest.com, questions and answers