# COMP 105: HW #4

You are welcome to discuss these questions with your classmates, the instructor, or a TA. However, if you make use of any outside information in answering these questions, or if you receive help from anyone, you need to acknowledge that along with your answer.
1. What is wrong with the following function? It is supposed to find and return the value of the largest integer in an array of integers. (There may be more than one problem with this function. Describe all errors that you find. Also, the errors are all logic errors - all of the statements are legal JavaScript.)
```
function returnLargest(array)
{
var largest = array[0];
for (var i = 0; i< array.length; i++)
{
if (largest > array[i])
{
largest = i;
}
}
}
```
2. How many times will the statement `doSomething();` be executed in the following loop?
```for (var i = 0; i < 6; i = i + 2)
for (var j = 0; j <= 4; j++)
doSomething(); //count how many times this line is executed.
```
3. How many different numbers can be represented with 13 binary digits? How many different numbers can be represented with 3 hexadecimal digits?
4. How is the decimal number 63 represented in
• binary?
• hexadecimal?
5. What are the decimal representations of
• the binary number 1001101 ?
• the hexadecimal number B9 ?
6. Show some work for exercises 4 and 5 so that I can see how you reached your answers.
7. The following is a binary representation of an ASCII encoded string. Each eight-bit byte represents one character. (This is actually UTF-8, a superset of ASCII. ASCII itself uses a 7-bit encoding.) Decode the string. If you use any outside tools, reference them in your answer.
```0100001101010011001100010011000000110101
```