# Homework Help: Help on couple of easy computer science questions?

1. Dec 15, 2011

### zzoo4

I got my old tests back today. And I don't understand what i did wrong??
p.s. teacher is not available at the moment( sub//part time teacher).

1. How much memory does it take to hold a 512x512 color image with 256 different levels of color(states)??

Okay, this one I just guessed and divided 8bits by 262144 which is totally wrong..

2a. what values of x will cause the following to be true??
if(x<100 && x>0 && x%2==1) for this i put 99..

b. if (x>=0 && x%5==0) for this i put 5.

c. if (Math.sqrt(x))%1 == 1 && x>1 && x<50 ) i put 12.25 (okay obviously this is wrong).

3. Create an example of short-circuit evaluation with an || (OR) statement = include variable with explanation.

i put if ((x==y) || (y==x) b/c if one condition is true, the other one must be true.

4. Create an example of a short-circuit evaluation with an && (AND) statement. Include values and explanation.

i put if ((x!=y) || (y=x) b/c only one condition needs to be false , then other is false.

help me fix what I did wrong please?

2. Dec 15, 2011

### Staff: Mentor

You need to show more work on these questions. We are not able to offer much help (within the PF rules) if you just say you guessed at answers and show no work.

That said, on 1a) Your guess makes absolutely no sense. How many bits does it take to encode 256 levels of color per pixel? And if you have 512x512 pixels, how many total bits is that? How many bytes is that?

3. Dec 15, 2011

### zzoo4

well, All I knew was bytes =8 bits. And there are 2^8= 256states..
I do not know what pixels are. And I just multiplied 256 by 256 and divided by 8bits.. Which wass wrong.
And for the rest of questions I am pretty sure that those don't really need work to be solved.

4. Dec 16, 2011

### Staff: Mentor

A pixel is each dot on your display. You are correct that it takes 8 bits or 1 byte to encode each of the pixels. If there are 512x512 pixels, then how many bytes does it take to hold that 512x512 image?

And no, on the rest of the problems you can definitely show work. Please try to work out 2b) here -- what do each of the terms mean in the question? What is the intersection of those terms?

5. Dec 16, 2011

### zzoo4

okay. I e-mailed the teacher, and I get how to do em now.

He said I got couple of them wrong due to questions have more answer.
for example.

2b. is 0 and all positive multiples of 5

6. Dec 16, 2011

### zzoo4

if (x>=0 && x%5==0) // since x is greater than and equal to 0 and divided by 5 gives no remainder. it has to be either 0 or and thing multiple of 5. ex. 55%5==0.
So there's clearly more answer than just the number 5.

o and all positive multiples of 5

7. Dec 19, 2011

### Staff: Mentor

Good. Can you do them all now?

8. Dec 20, 2011

yessirr