210sync to upload all your code to the github.
210sync to download all your code to
the github.
210sync is essentially downloading the code in the github
and then uploading the new code to the github.
It's a good idea to always start and end any period of work that you do (either in a VM or a class workstation), by syncing up with the git.
lab02. All source
code (.cpp) files for Parts 1, 2, and 3 should be created in that directory.
The actual value of a number depends on both what digits are used, and the location of the digits. Obviously, the number 123 is smaller than the number 321. In particular the farther left a digit is, the more contribution it makes to the size of the number. If we number the columns from right to left, starting with 0, then when the base is b and the digit d is in column c, the contribution of that digit to the value of the number is d*bc. For example the number 123 base 10 (written 12310) can be written as follows:
The reason you're reading all this is because computers don't store their numbers in base 10, but rather in base 2 (the only digits are 0 and 1).
As computer programmers, we need to be able to convert numbers from the binary (base 2) format to the decimal (base 10) format. That is what you will do for the lab.
You will write a program (use filename p1.cpp)
that converts a number from binary to decimal format and prints out the
decimal value of that number. In particular your program will:
$ ./p1 Enter a 4-bit binary number: 1101 In decimal 1101 = 13
submit as: ~/bin/submit -c=IC210 -p=lab02 p1.cpp
p2.cpp) that converts a number from decimal to
binary format.
Answers to the following questions will help you figure out your solution to this part:
$ ./p2 Enter a number between 0 and 15: 13 13 in binary is 1101
submit as: ~/bin/submit -c=IC210 -p=lab02 p1.cpp p2.cpp
In each lab, there will be parts labeled with "going further". In general, these parts will be a bit more challenging.
In Unix, file permissions are normally set with the command chmod with a three digit number as an argument. For example, if you have a file foo.sh, you might set its permissions like this:
chmod 754 foo.shThe way this is interpreted is that each digit is a "bit mask", meaning that its numeric value is not important, rather its bit-representation is what really matters. In fact, each digit must be in the range 0-7, which means they are three-bit numbers. The first (leftmost) bit tells you whether or not read access is granted (1 means yes, 0 means no). The second gives the write access permissions. The third gives the execute (i.e. as a program) permissions. So, for example, 6 as a 3-bit number is 110 which means read is on, write is on, execute is off.
So why are there three digits? The first (leftmost) digit is for "User" permissions, which means the user who owns the file. The second digit is for "Group" permissions. Users can be placed into groups, and this specifies the access permissions for other users who are in the same group. Finally, the third digit specifies the access permissions for "Other", meaning users other than the owner and members of the same group.
Your job is to write a program (use
filename p3.cpp) that reads in a chmod triple
(e.g. 754) and print a summary of the permissions as shown in the
example execution below.
$ ./p3 Permissions: 754 User: read 1 write 1 execute 1 Group: read 1 write 0 execute 1 Other: read 1 write 0 execute 0
submit as: ~/bin/submit -c=IC210 -p=lab02 p1.cpp p2.cpp p3.cpp