Change Contents of the Bubble
Welcome to CS1315. Click on the python to add comments.

This page removed for FERPA compliance
View this PageEdit this Page (locked)Uploads to this PageHistory of this PageHomeRecent ChangesSearchHelp Guide

Midterm Exam 2 Review Fall 2003: What's the underlying representation?

Answers? Comments? Questions on Answers? Questions on Comments?

(Back to Fall2003 Midterm Review 2)



For each of the below, see if you can figure out the representation in terms of bits and bytes.

1. Internet addresses are four numbers, each between 0 and 255. How many bits are in an Internet address?
2. In the programming language Basic, lines can be numbered, each one between 0 and 65535. How many bits are needed to represent a line number?
3. Each pixel's color has three components: Red, green, and blue, each of which can be between 0 and 255. How many bits are needed to represent a pixel's color?
4. A string in some systems can only be up to 1024 characters. How many bits are needed to represent the length of a string?

Here is what I came up with...

A bit is simply a one or a zero in binary- so the answers (I hope) are as follows.

It takes 8 bits to represent the numbers 0-255 00000000 - 11111111 (in binary)- so, four numbers 0-255 would take 8X4 = (32 bits)

For the line number... 65535 in binary is 1111111111111111 - 16 ones. Thus it takes 16 bits to represent the line number.

We figured out in the first question that to represent 0-255 it takes 8 bits. In this case we have 3 sets of 8 bits- 8X3 = 24 Bits... (REMOVEDke the 24 Bit color in display options "True Color")

1024 in Binary is 1111111111 - 10 ones- So we need 10 bits to represent the length up to 1024.

Student549



pls. correct me if i am wrong.......

All of my answers are in a range & based upon one character has 8bits.

1. For each number, the range is from 8-24bits(0 is 1 character & 255 is 3 characters). So, for 4 numbers, the range is 32-96bits.
2. 0 is one character & 65535 is 5 characters. So each line # has range 8-40bits.
3. (8-24) bits 3 = 24-72bits
4. 18-10248 = 8-8192bits


You're confusing bits and characters. Look at Greg's answer. Mark Guzdial


I'm probably just forgetting something we've already learned, but how does Greg know the binary representations for those answers? His explanations make sense to me, but I don't know that I could have come up with them on my own.

Think about it this way: At what value of "n" does 2^n give a value greater than or equal to 65535 or 1024? 2^8 is 256. 2^9 is 512. 2^10 is 1024 – BINGO for one! 2^11 is 2048. 2^12 is 4096. 2^13 is 8192. 2^14 is 16384. 2^15 is 32768 (remember this one from samples?). 2^16 is 65536 – BINGO for the second! Mark Guzdial


So, in other words, all we have to do to figure out how many bits are used to encode a certain number is figure out what power to raise 2 to, that equals the biggest number encoded?
ex:
1)2^n=255
2)2^n=65535
3)2^n=255
4)2^n=1024

This makes no sense to me at all...I can guess around until I figure out what to raise 2 to to get 65535, but I don't have any idea where that number came from...how do I figure out what number I'm trying to arrive at when I raise 2's to a power.

I may be wrong but are there 8 bits to every byte meaning that Greg's answers would all be divided by 8 to give us the number of bytes?

1. 32/8 = 4 bytes
2. 16/8 = 2 bytes
3. 24/8 = 3 bytes
4. 10/8 = 1.25 bytes

You use the number 2 when raising 2^n becasue this is binary, bi meaning 2. If this were octal you would use 8 or if it were hexadecimal you'd use 16. You figure out what number to arrive at by what is in the question. For example in number 3, you have to arrive at 255, but since you use red, green, and blue, you have to multiply by 3, hence giving you an answer of 24.

Yes, I just left out the bytes... you will note that in ASCREMOVED there are 256 characters so they can be represented by 8 bites / 1 byte... I am not sure if this is why we have settled on 8 bits in a byte, but that's how I always think of a byte.
Student549



Remember in the book that n bits can represent values up to 2^n. That's where the equation comes from. 8 bits is enough to represent all the characters needed (for English), so that's how bytes came to be defined. Mark Guzdial




Link to this Page