{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

C_Crib_Sheet_Final_Exam[1][1]

C_Crib_Sheet_Final_Exam[1][1] - Chapter 1 Twos Complement...

Info icon This preview shows pages 1–3. Sign up to view the full content.

View Full Document Right Arrow Icon
Chapter 1 Two’s Complement Form - For signed integers, the leftmost bit is used for sign. 0 for positive and 1 for negative. Ex: Convert the 2’s complement integer 10101100 to decimal. Solution: Find the absolute value of the integer by changing each 1 to 0 and each 0 to 1. 01010011 Then add 1 to this number. 01010011 + 1 01010100 01010100 = 64 + 16 + 4 = 84 The original bit string 10101100 represents the decimal number -84 . Floating-Point Numbers - A number with a decimal point, such as 8.3194 or 6.34 X 10^20 (scientific notation) . 6.34 => ( Mantissa ) 10 => (Base) 20 => (Exponent) IEEE – single-precision standard- represents a floating-point number in one 32-bit word. 1 st bit - (s) represents the sign bit. 0 => (+), 1 => (-) 2-9 bits - are interpreted as an unsigned integer e’. If e’≠ 0, the exponent is defined as e’ – 127. If e’ = 0, the exponent is defined as -126. 10-32 bits – are interpreted as the value m’ = 0.b 1 b 2 ….b 23 in base 2, that is m’ = b 1 *2 -1 + b 2 *2 -2 + … + b 23 *2 -23 So. If e’ ≠ 0, the mantissa is 1+m’, and the number represented is: (-1) s * (1+m’ ) * 2 (e’-127) If e’ = 0, the mantissa is m’, and the number represented is: (-1) s * m’ * 2 -126 EX: 0 10101100 1001101000000000000 (spaces included for clarity). The leading 0 indicates a (+) num. 10101100 = 172. so e’ = 172 - 127 = 45 . m’= 1*2 -1 + 1*2 -4 + 1*2 -5 + 1*2 -7 =.578125 and the number represented is 1.578125 * 2 45 Chapter 2 preprocessor directive – request some action before the program is actually translated into machine code. #include <stdio.h> header file – files with .h extensions. functions – a C program consists of one or more functions, exactly one of which is called main . variables – all C variables must be defined, which in C is to request storage for a particular data type. identifier – is the official word for name in a high- level language. An identifier in C must satisfy to following requirements. 1. It must start with a letter or an underscore. 2. It must consist of only letters, digits 0-9, and the underscore. 3. It must not be a keyword such as int or while . while statement while (expression) action EX: int x; x = 0; while ( x != 2) x = x + 1; printf ( “x = %d \n”, x); * the printf is not included in the while construct. If no {} are used, only the 1 st statement after while is executed.
Image of page 1

Info icon This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
do while statement do action while (expression); * similar to while statement, except the body of the loop is always executed at least once. EX: do { printf ( “Enter a positive integer: “); scanf ( “%d”, &x);} while ( x <= 0 ); * This will keep prompting the user to enter a positive integer until they do. if statement if (expression ) action EX: int code = 1; if ( code == 1) printf ( “ code = 1 \n “); else printf ( “ code not to equal 1 \n “); Files and Redirection of I/O file pointers – are required for each file to be handled in a program. EX: FILE *fin, *fout fopen – is then used to open a file. fin = fopen ( “ infile.dat ” , ” r ”); fout = fopen ( “ outfile.dat ” , “ w “ ); Input from file fscanf ( fin , “ %type “, & variable ); Output to file fprintf ( fout,“ variable is: %type “, variable ); Close files at the end of program : fclose (fin), fclose (fout) Chapter 3 Description Operator Assoc.
Image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern