AP Computer Science - Are Hexadecimal and Binary Tested?

<p>Hello,</p>

<p>Apologies in advance if this is in the wrong forum or if there is already a thread for this, but I couldn't find anything.</p>

<p>Anyways, I was just wondering if the AP Computer Science A exam tests either hexadecimal or binary and what we need to know about the two. My teacher never went over this with us, so I am starting to get worried quite a bit. </p>

<p>Thanks,
Eobaggs</p>

<p>I am very sure there won’t be hexadecimal on it. There may be binary though.</p>

<p>Neither. Contrary to what you may have been told, hex and binary aren’t actually used in introductory computer science, which AP very much is.</p>

<p>Thanks a bunch! I just spent like an entire hour trying to figure out how to do them because they are in the Barron’s book. What a waste.</p>

<p>Can anyone else confirm this though? Because in the Barron’s 2010 edition, there are questions on these topics in the sample exams.</p>

<p>I thought we need to know binary, but not hexadecimal. And I’m using Barron’s book right now, and the book seems to cover too many topics. At the end of each section, it says “You will not be tested for this on AP” :(</p>

<p>Yeah, exactly. It’s starting to annoy me, really. Can anyone offer some clarification?</p>

<p>Neither topics.</p>

<p>Okay, I just looked at the [course</a> description](<a href=“Supporting Students from Day One to Exam Day – AP Central | College Board”>Supporting Students from Day One to Exam Day – AP Central | College Board) on the College Board Website and it said the following:</p>

<p>Students should understand the representation of positive integers in different bases, particularly decimal, binary,hexadecimal, and octal</p>

<p>Really? Because I have never seen any question about that on any sample test, and my course lists them as optional extra material.</p>

<p>I was under the assumption that you had to know them, but if they were actually on the exam, it would be one or two questions at most. It’s really not that complicated.</p>

<p>I have done a lot of tests and I haven’t seen any questions on it. However, I can explain it to you here just so you understand it anyway.</p>

<p>We use a decimal system, known as “base 10.” Remember way back when in elementary school when you had to line up your numbers in columns – so like the number 234 was a 2 in the hundreds column, a 3 in the tens column, and a 4 in the ones column – 200 + 30 + 4 = 234. The basic idea of the column is that once you reach the maximum (in the decimal system the max is 10), you start the column over and increase the next column by one.</p>

<p>Binary works exactly the same way, except instead of a cap at 10, there is a cap at 2. Just like you had columns that were multiples of 10 before (1, 10, 100, etc = 10^0, 10^1, 10^2, etc), now you have columns that are multiples of 2 (1, 2, 4, etc = 2^0, 2^1, 2^2, etc). So 0 would jut be represented by a single 0, and 1 would just be represented by a 1. However, what about 2? Think back to the decimal system – when you got to 10, what do you do? Increase the next column by 1 and restart this column. Same thing here. Therefore, 2 would be represented as “10” (one 2, zero 1s). In short, binary is like counting with 2 fingers instead of 10 :P</p>

<p>Converting from Decimal to Binary
To convert from decimal to binary, simply make a table starting from the highest power of 2 less than your decimal number and extend the table all the way down to the 1s column. Then start distributing your decimal number into the columns, and when it is distributed completely then you have a binary result. Here’s an example:</p>

<p>Take the number 87. The highest power of 2 less than 87 is 64. So make 7 columns: 64s, 32s, 16s, 8s, 4s, 2s, and 1s. Start at the 64s. You know that there is definitely a 64 inside 87, so put a 1 in the 64’s column. 87-64=23. Since 32 is greater than 23 you know there are no 32s, so put a 0 in the 32’s column. Next column is 16, which is less than 23, so put a 1 in the 16’s column. 23-16=7. Since 8 is greater than 7 you know there are no 8s, so put a 0 in the 8’s column. Next column is 4, which is less than 7, so put a 1 in the 4’s column. 7-4 =3. Next column is 2, which is less than 3, so put a 1 in the 2’s column. 3-2=1. Next column is 1, and since there is in fact 1 left over, put 1 in the 1s column. What you are left with is the binary representation of 87: 1010111</p>

<p>Converting Binary to Decimal
Just take the same table method you worked with and apply it to the binary number. Determine what numbers are contained in the decimal number and add them together. Here’s an example:</p>

<p>Take the number 1010111. If you place it into a table, you find that there is a 1 in the columns 64, 16, 4, 2, 1. Now add up those columns: 64+16+4+2+1 = 87. Success!</p>

<p>The Hexidecimal system works exactly the same way and has the same approaches involved so I won’t give an example of conversion. However, what you should know is just as the cap for binary is 2 and the cap of decimal is 10, the cap of hexidecimal is 16. But of course, our digits only go up to 9, so how are we going to represent 10-15 in a column before it reaches its cap? We turn to letters. In binary the only options to place in a column were 0 or 1. In decimal the only options to place in a column were 0-9. In hexidecimal the options are 0-F (0-9, A (10), B (11), C (12), D (13), E (14), F (15)). Naturally once you reach 16, you reset the count of the column and increase the next by one.</p>

<p>Hopefully this was clear, but you probably don’t have to worry about this stuff for the test. There are also faster conversion methods that I know but I don’t want to confuse you and these are the most straightforward methods :P</p>

<p>According to my teacher, both are tested, but it’s super basic - we covered all you needed to know in one class session.</p>

<p>Just learn them, they’re easy as hell. You can learn 'em in like 5 mins.</p>

<p>Although I’m not taking Computer Science A, I’m guessing that hexadecimal and binary are Computer Science AB materials and are incorporated into Computer Science A this year since AB was discontinued as stated somewhere in the course description.</p>

<p>A number with n digits can be represented this way:</p>

<pre><code> db^(n-1) + db^(n-2) + … + db^3 + db^2 + db^1 + db^0
</code></pre>

<p>where:
b is the base value
d is the digit value (ranges from 0 to (b-1))
* is multiplication sign
^ is the exponent sign</p>

<p>Notes: The exponent value increases from right to left. The leftmost digit is the most significant digit.</p>

<p>In the decimal system b = 10, d ranges from 0 to (10-1) or 0 to 9. This means in the decimal system, a digit value can be only 0,1,2,3,4,5,6,7,8,9</p>

<pre><code>9876543 = 910^6 + 810^5 + 710^4 + 610^3 + 510^2 + 410^1 + 310^0
= 9
1000000 + 8100000 + 710000 + 61000 + 5100 + 410 + 31
= 9000000 + 800000 + 70000 + 6000 + 500 + 40 + 3
= 9876543 (decimal, off course)
</code></pre>

<p>In the binary system b = 2, d ranges from 0 to (2-1) or 0 to 1. This means in the binary system, a digit value can be only 0 or 1.</p>

<pre><code>11111111= 12^7 + 12^6 + 12^5 + 12^4 + 12^3 + 12^2 + 12^1 + 12^0
= 1128 + 164 + 132 + 116 + 18 + 14 + 12 + 11
= 128 + 64 + 32 + 16 + 8 + 4 + 2 + 1
= 255 (decimal)

10000000= 12^7 + 02^6 + 02^5 + 02^4 + 02^3 + 02^2 + 02^1 + 02^0
= 1128 + 064 + 032 + 016 + 08 + 04 + 02 + 01
= 128 + 0 + 0 + 0 + 0 + 0 + 0 + 0
= 128 (decimal)
</code></pre>

<p>In the hexadecimal system b = 16, d ranges from 0 to (16-1) or 0 to 15.
This means in the hexadecimal system, a digit value can be only 0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15
To simplify thing, people use A for 10, B for 11, C for 12, D for 13, E for 14, and F for 15</p>

<pre><code>FFFF = F16^3 + F16^2 + F16^1 + F16^0
= 1516^3 + 1516^2 + 1516 + 151
= 154096 + 15256 + 15*16 + 15
= 61440 + 3840 + 240 + 15
= 65535 (decimal)

FE0A = F16^3 + E16^2 + 016^1 + A16^0
= 1516^3 + 1416^2 + 016 + 101
= 154096 + 14256 + 0*16 + 10
= 61440 + 3584 + 0 + 10
= 65034 (decimal)
</code></pre>

<p>It’s very easy to convert from binary to hex. To convert from binary to hex, separate the binary digits into groups of 4 digits from right to left.
Then convert the 4-digit group into a decimal number. Then convert the decimal number into hex.</p>

<p>Ex: 11111111 (binary) = 1111,1111 (2 groups of 4 digits)
= 15 ,15 (2 decimal numbers)
= F ,F
= FF (hex)</p>

<pre><code> 1110100111 (binary) = 11,1010,0111 (3 groups of 4 digits)
= 3, 10, 7 (3 decimal numbers)
= 3, A, 7
= 3A7 (hex)
</code></pre>

<p>Similarly, to convert a hex number to binary, expand each hex digit into a 4 binary digit group.
Add zeros to left of the group if the expansion does not result in 4 binary digits.</p>

<pre><code>3A4E = 11, 1010, 100, 1110
= 0011, 1010, 0100, 1110 (2 zerors are added to the first group, 1 zero is added to the third group)
= 0011101001001110 (binary)
</code></pre>

<p>I guess it is important to realize that non-integers are represented in the computer in binary, and what that means. For instance, a Java variable cannot actually store the exact number .2, because .2 has no finite binary representation. Because of things like that, you get the bane of all programmers, roundoff error.</p>

<p>Well, the bane of all programmers is the null pointer exception/dereferencing a null pointer/whatever your language likes to call it. But roundoff error comes in second for sure.</p>

<p>@Jerry4445 No they were part of the A curriculum when I took the test last year.</p>

<p>oh, I guess I was wrong.Thx for correcting me.</p>

<p>@Darkeyes wow thanks a lot for that!! rly helped!</p>

<p>I also am taking the AP CS A exam, and I’m kind of wondering, if hexadecimal & binary are on there, what else is on there that I don’t know about?
I have the Barron’s book, and I’m working through that, but it’s really thin. Can anyone else think of good review books for AP CS A? I have the Princeton Review, but it’s 3 years old. :stuck_out_tongue:
Thanks!!</p>