12.07.2015 Views

williams-et-al-1983-apple-ii-computer-graphics

williams-et-al-1983-apple-ii-computer-graphics

williams-et-al-1983-apple-ii-computer-graphics

SHOW MORE
SHOW LESS
  • No tags were found...

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

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

166 APPLE II COMPUTER GRAPHICSThen convert each hex digit to decim<strong>al</strong> which gives you(8 x 4©96) + (9 x 256) + (1 © x 16) + (1 1 x 1) = 35243.There is a variation on this m<strong>et</strong>hod which is handy when you are proficientwith hex bytes. When de<strong>al</strong>ing with bytes, rec<strong>al</strong>l from Chapter 2 we mentionedthat two hex digits could be used to represent one base 256 digit.Then the address given by $FF3A can be c<strong>al</strong>culated as($FF x 2561) + ($3A x 256°)= (255 x 256) + (58 x 1)= 35243To use this idea efficiently, you must know or be able to quickly c<strong>al</strong>culat<strong>et</strong>he v<strong>al</strong>ue of numbers like $3A-a skill that comes with practice.The expanded fo rm m<strong>et</strong>hod <strong>al</strong>so works when converting binary to decim<strong>al</strong>,but since binary is base two, you g<strong>et</strong> two to <strong>al</strong>l those powers insteadof sixteen. From right to left in binary, the first position is the ones (2°)place, then the two's (21) place, the four's (22) place, the eight's (23) place,and so on. Therefore, you may write ! 1 1 ©1 ©1 as(1 x 25) + (1 x 24) + (© x 23) + (1 x 22)+ (© x 21) + (1 x 2°)Or even simpler, since it is either one or zero times the place v<strong>al</strong>ue32 + 16 + 4 + 1= 53This was c<strong>al</strong>culated by adding the place v<strong>al</strong>ues with ones in them, andignori ng the places containing zeros.Wonderfu l, but you <strong>al</strong>ready knew how to convert from binary and hexto decim<strong>al</strong>. These ideas will help you to become more fam iliar with whatyou are doing, and make you faster and more flexible in your conversions.Conve rting to decim<strong>al</strong> is fairly straightforward, but unfortunately the sameis not true of converting from decim<strong>al</strong> to binary or hex.Decim<strong>al</strong> ta BinaryWhen converting to binary, you can start by fi nding the highest power oftwo which will go into the decim<strong>al</strong> number-if you can g<strong>et</strong> your hands ona c<strong>al</strong>culator, now would be a good time to do so. L<strong>et</strong>'s take 421 as anexample to convert: 29 (512) is too large to divide by 421, but 28 = 256 (anumber to know in computing), and 256 will divide 421, <strong>al</strong>beit with aremainder of 165 (42 1-256), so we have a 1 in the 28 place which will beon the left end of our binary number. The next lowest power of two is 128,which divides 165 leaving a remainder of 37. So far our binary number is11 xxxxxxx. Dropping to the next power of two (64) we see that it will notdivide the present remainder (37) so we put a zero in the next place in our

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

Saved successfully!

Ooh no, something went wrong!