13.03.2013 Views

Hacking the Xbox

Hacking the Xbox

Hacking the Xbox

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Chapter 2 - Thinking Inside <strong>the</strong> Box 43<br />

Binary and Hexadecimal Numbers<br />

Digital circuits use 1’s and 0’s to represent numbers. This binary, or<br />

“base-2”, notation is a reflection of <strong>the</strong> way electrical signals are<br />

used to represent numbers: two ranges of voltage levels are used<br />

to define one logic state or <strong>the</strong> o<strong>the</strong>r. It is possible to build electrical<br />

systems that represent information using more than two voltage<br />

levels, but only at <strong>the</strong> cost of power and complexity. Modern modems,<br />

for example, use multiple voltage levels and phase information<br />

to represent multiple bits of data in a single time unit.<br />

Number composition and arithmetic in binary follows <strong>the</strong> same<br />

rules as our familiar decimal (“base-10”) representation. In decimal,<br />

0’s are used as placeholders to remember when a digit has overflowed.<br />

For example, 1 more than 9 leads to an overflow because<br />

<strong>the</strong>re is no single digit bigger than 9. Hence, <strong>the</strong> number 10 records<br />

that we had one overflow of <strong>the</strong> right-most decimal location. Likewise,<br />

in binary, 1 more than 1 is 10, since <strong>the</strong> largest single digit in<br />

binary is 1.<br />

Thus, in decimal, <strong>the</strong> value of a four-digit decimal number d d d d 4 3 2 1<br />

can be broken down as:<br />

d * 10 4 3 + d * 10 3 2 + d * 10 2 1 + d * 10 1 0 = d * 1000 + d * 100 + d * 10 + d * 1<br />

4 3 2 1<br />

Likewise, a four-digit binary number b b b b can be broken down<br />

4 3 2 1<br />

as:<br />

b * 2 4 3 + b * 2 3 2 + b * 2 2 1 + b * 2 1 0 = b * 8 4 + b * 4 3 + b * 2 2 + b * 1 1<br />

For example, <strong>the</strong> number 1010 = 1*8 + 0*4 + 1*2 + 0*1 = 10 decimal.<br />

Keeping track of numbers in straight binary can become cumbersome<br />

quickly; for example, to represent decimal 968, you need ten<br />

binary digits. To save on screen space, binary numbers are converted<br />

to octal or hexadecimal. The octal format, or “base-8”, was<br />

popular in <strong>the</strong> early days of computers, but has since become a<br />

rarity. Hexadecimal, or “base-16”, is <strong>the</strong> de-facto numbering system.<br />

There are 16 digits in hexadecimal, so <strong>the</strong> hex digits that correspond<br />

to decimal numbers 10 through 15 are represented by <strong>the</strong><br />

letters A through F. Table 2-2 summarizes <strong>the</strong> conversion between<br />

binary, decimal, and hexadecimal for <strong>the</strong> first 16 positive integers.<br />

In order to differentiate hexadecimal from decimal numbers, many<br />

people use <strong>the</strong> C language convention where 0x[number] represents a<br />

hexadecimal number, and [number] is implicitly a decimal number. Binary<br />

numbers have no similar standard to draw from in C, so some<br />

people use <strong>the</strong> Verilog standard, [digits]’b[number], where [digits] is <strong>the</strong><br />

number of digits in <strong>the</strong> binary number. The suffix “b” after a string of 1’s<br />

and 0’s, such as 1010.1100.1110b is also used to denote a binary number.<br />

Notice how a “.” was used to group <strong>the</strong> binary digits into sets of four;<br />

this assists in mentally translating <strong>the</strong> binary number into hexadecimal:<br />

0xACE.<br />

(continued)

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!