05.01.2013 Views

hide - Understanding jQuery

hide - Understanding jQuery

hide - Understanding jQuery

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Incrementing a Binary Number<br />

Step Dec. Binary Commentary<br />

A 0 00000000<br />

B 1 00000001<br />

C 1 00000001<br />

D 2 00000010<br />

E 3 00000011<br />

F 3 00000011<br />

G 4 00000100<br />

H 5 00000101<br />

I 6 00000110<br />

J 7 00000111<br />

K 8 00001000<br />

L 9 00001001<br />

M 10 00001010<br />

N 11 00001011<br />

O 12 00001100<br />

P 13 00001101<br />

Q 14 00001110<br />

R 15 00001111<br />

S 16 00010000<br />

We begin with a clean slate. This is 0 in binary and decimal.<br />

Start by switching the right-most bit to on position. Another<br />

way of thinking about it is that we shift 1 left into the number.<br />

To increment by 1, start by shifting this bit to the left.<br />

A zero to the right is now open. We just incremented the value<br />

by one. The equivalent of 00000010 in decimal is 2.<br />

Before we move on we first need to fill in remaining zeros to<br />

the right. Note that 3 isn’t 00000100. That’s a common mistake.<br />

We ran out of space. So, the next step is to move the leading 1<br />

to the left again, and zero out everything to the right.<br />

This is 4 in decimal.<br />

The process repeats itself.<br />

It looks like we exhausted all combinations. Just like in step G,<br />

we shift left and zero out again.<br />

11 is 1011 and not 1100 because we are always concerned with<br />

filling in the two right-most 0s first. See steps A-J. Same thing.<br />

Zero out.<br />

Shift left.<br />

Zero out.<br />

29

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

Saved successfully!

Ooh no, something went wrong!