CISC181 010-012 09/12/05 05F If you notice that a file on the web site comes up with the message "permission denied", please send Prof. Conrad an email and he will fix it. (0) Auto-save files and tilde files in emacs In class, I demonstrated that while editing the file 09.12.txt, the tilde file is always the previous version of what I saved. The 09.12.txt file is the current saved version. If if go in and edit, and have unsaved changes, periodically, emacs will save an intermediate version for me in a file that starts and ends with the pound sign (#). > ls 09.12.txt 09.12.txt~ [right here, I went into emacs, made a change, and waited a couple of minutes. then typed ls again...] > ls #09.12.txt# 09.12.txt 09.12.txt~ > Notice the #09.12.txt# file. If "red x" out of ssh, that is, if I exit improperly, the #09.12.txt# file will stick around. If on the other hand, instead of exiting emacs with the red x, I save my file properly, then the #09.12.txt# auto save file will go away by itself. In fact, everytime you save your unsaved changes, the auto save file automatically goes away. Attendance: (1) Calendar is online. (2) Conversion from decimal to binary by hand 271 in decimal is what in binary? 271 - 256 = 15 15 - 8 = 7 7 - 4 = 3 3 - 2 = 1 1 - 1 = 0 So the bits are 256, 8, 4, 2, 1 as shown here: 512 256 128 64 32 16 8 4 2 1 0 1 0 0 0 0 1 1 1 1 (3) Meaning of % and / with integers in C, C++, Java % is remainder after division. (4) A technique to convert from decimal to binary using % and / 271 % 2 => 1 271 / 2 => 135 135 % 2 => 1 135 / 2 => 67 67 % 2 => 1 67 / 2 => 33 33 % 2 => 1 33 / 2 => 16 16 % 2 => 0 16 / 2 => 8 8 % 2 => 0 8 / 2 => 4 4 % 2 => 0 4 / 2 => 2 2 % 2 => 0 2 / 2 => 1 1 % 2 => 1 1 / 2 => 0 What we get from the results of the % operations is the bits of the number we started with, in reverse order. (From least significant to most significant). 512 256 128 64 32 16 8 4 2 1 0 1 0 0 0 0 1 1 1 1 Can we make this a function? Use a C string as our target: char binaryAnswer[9]; Limitations: min 0 minimum value for decimal input max 255 maximum value for decimal input number of bits in binary answer 8 represent the binary answer as a C string char binaryAnswer[9]; Note the role of \0 '0' in binary is 0010 1000 '1' in binary is 0010 1001 '\0' in binar is 0000 0000 [null terminator] void computeBinary (int decVal, char binAns[9]) { for (int i = 0; i<8, i++) binAns[i] = '0'; binAns[8] = '\0'; @@@ FILL IN DETAILS HERE return; }