Anda di halaman 1dari 2

# Mec 102 - HW 1 Michael Lam

1. To convert to base 10, first we multiply each digit by successive powers of 2, and

## add it out like so: . For the other numbers, we

do the same thing but instead of using powers of 2 we use powers of 8 and 16

## for base 16,

2. To convert to base 2, first we find the highest power of 2 that can be subtracted from

, which is actually or 8, which takes up the 4th digit in a base 2 system like so:

. For , it’s mostly the same process, the highest power of 2 is still 8, but there

is still a remainder of 2, which conveniently is also a factor of 2, which will take up the

2nd digit: . is also convenient because 16 is just , it will take up the 5th

digit:

3. The two’s complement is a way of expressing negative numbers in binary. How it works

is that a number in a base 2 system, will first have their bits negated (so 1 becomes 0, and

0 becomes 1), and then a 1 is added to the number. For we can calculate the two’s

## get . After that we add a 1 to this, resulting in which is the two’s

complement

4. There are 8 bits in a byte. As text, each character in a word is a single byte, so

## unsigned long integer which is 32 bits or 4 bytes also known as a word.

5. “a=single(135467.214); b=single(135467.211); a-b” gives a result of 0 because the code

specifies single precision format, which doesn’t store floating point numbers. Those two

numbers are functionally the same in single precision format, so subtracting them is 0

6. “i=int8(4); j=int8(3); i/j” gives a result of 1, because “int” signifies an integer answer,

since there can’t be any decimals, they are rounded down, and 8/3=1.33 rounds to 1.

## 7. From my understanding, it seems like compiled languages directly give commands to

machines by compiling source code into something a computer can read, but interpreted

language requires the machine to directly parse the code and execute commands. A pro

about interpreted languages are that they’re easy to understand and analyze, but their

main drawback is that they are a lot slower than compiled languages.

## 8. MATLAB is an interpreted language that is very effective at doing operations with

matrices, which is why it’s called MATrix LABoratory. It can also be used to write

simple programs, and has a pretty friendly UI. The pros of MATLAB include the fact that

it’s easy to use and understand, and that it has a wide variety of practical applications.