Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 12

CSC 1303 Midterm Study Guide

electronic stored value


circuits is preserved
o Provide the  Hexadecimal
building blocks notation: A
 Chapter 1 from which shorthand notation
Data Storage computers are for long bit patterns
constructed o Divides a pattern
 Bit: Binary Digit o VLSI (Very into groups of four
(0 or 1) Large Scale bits each
 Bit Patterns are Integration) o Represents each
used to represent A pictorial group by a single
information representation of AND, symbol
o Numbers OR, XOR, and NOT o Example:
o Text characters gates as well as their 10100011 becomes
o Images input and output values A3
o Sound o Was on quiz 1
o And others
 Boolean
Operation: An
operation that
manipulates one or
more true/false
values
 Specific operations
o AND
o OR
o XOR  Flip-flop: A circuit
(exclusive built from gates
or) that can store one
bit.
– One input  Cell: A unit of
line is used main memory
to set its (typically 8 bits
stored value which is one byte)
to 1 o Most significant
– One input bit: the bit at the
line is used left (high-order)
to set its end of the
stored value conceptual row of
o NOT to 0 bits in a memory
 Gate: A device that – While both cell
computes a Boolean input lines o Least significant
operation are 0, the bit: the bit at the
o Often most right (low-order)
implemented as recently end of the
(small) conceptual row of
CSC 1303 Midterm Study Guide
bits in a memory o Example: 3 GB = 3  Representi
cell. times ng Text
 Address: A 1,073,741,824 o Each
“name” that bytes. character
uniquely identifies  Mass Storage (letter,
one cell in the o Additional devices: punctuation,
computer’s main o Magnetic etc.) is
memory disks assigned a
o The names are o CDs unique bit
actually numbers. o DVDs pattern.
o These numbers are o Advantages over o ASCII:
assigned main memory Uses
consecutively o Less patterns of
starting at zero. volatility 7-bits to
o Numbering the o Larger represent
cells in this manner most
storage
associates an order symbols
capacities
with the memory used in
o Low cost
cells. written
o In many
 Random Access English text
cases can be o ISO
Memory (RAM):
removed
Memory in which developed a
 Flash Drives
individual cells can number of 8
o Flash
be easily accessed bit
in any order Memory – extensions
o Dynamic Memory circuits that to ASCII,
traps each
(DRAM): RAM
electrons in designed to
composed of
tiny silicon accommoda
volatile memory.
dioxide te a major
 Measuring
chambers language
Memory Capacity
o Repeated group
o Kilobyte: 210
erasing o Unicode:
bytes = 1024 bytes
slowly Uses
o Example: 3 KB = 3
damages the patterns up
times1024 bytes media to 21-bits to
o Megabyte: 220 o Mass represent
bytes = 1,048,576 storage of the symbols
bytes choice for: used in
o Example: 3 MB = 3 o Digital languages
times 1,048,576 cameras worldwide,
bytes o SD Cards 16-bits for
o Gigabyte: 230
provide world’s
bytes = GBs of commonly
1,073,741,824 storage used
bytes
languages
CSC 1303 Midterm Study Guide
– Used for
• Representing high quality
Numeric Values recordings
• Binary notation: – Records
Uses bits to actual audio
represent a number • MIDI
in base two – Used in
• Limitations of music
computer synthesizers
representations of – Records
numeric values “musical
– Overflow: score” Figure 1.22 An excess eight
occurs  The Binary System
when a o The traditional conversion table.
value is too decimal system is
big to be based on powers of
represented ten.
– Truncation: o The Binary system
occurs is based on powers
when a of two.
value The base ten and binary
cannot be
represented systems
accurately
– Representin
g Images
• Bit map
techniques
– Pixel: short
for “picture
element”
– RGB
– Luminance
and Storing Integers Two’s
chrominanc complement notation: The
e most popular means of
• Vector techniques representing integer values
– Scalable Excess notation: Another
– TrueType means of representing
and integer values
PostScript Both can suffer from
– Representin overflow errors Figure 1.23 An excess
g Sound notation system using bit
• Sampling Two’s complement patterns of length three
techniques notation systems
Was on quiz 1
CSC 1303 Midterm Study Guide
1110012 = 1
1

1⋅25+1⋅24+1⋅23+0 1
0
8
⋅22+0⋅21+1⋅20 = 0
0

5710 1
0
9
A) 0101 = 0
1

 Floating-point
0∙2 +1∙2 +0∙2 +1∙2  
3 2 1 0
1
o Notation: Consists = 0+4+0+1 = 5 0
1
1
0
of a sign bit, a 0
B) 1101 =
mantissa field, and
1∙23+1∙22+0∙21+1∙20 = 1
an exponent field. 0 1

o Related topics 8+4+0+1 = 13 1


1
1

include C) 01001101
1
o Normalized form = 0∙27+1∙26+0∙25+0∙24+1∙23+1∙ 1 1
0 2
o Truncation errors 22+0∙21+1∙20 = 0
0+64+0+0+8+4+0+1 = 77
1
What was on Quiz 1 1 1
Binary to decimal 0 3
1
Fill in the blank conversion table
1
1 1
1 4
0
D
B
e 1
i 1 1
c 1 5
n
i 1
a
m
r 1
a
y 0
1
l 0
6
0
0
0 0

1
1 1 0
1
0
7
1 0
2
0 1

1 1
3
1 0
1
0
8
1
1
Binary Number System 0 4
0
0
Example: find the 1
decimal value of 1
0
0
1
0 5 9
1110012: 1
1
1
binary
1 1 1 0 0 1 1
number: 1
1 6
0
0 2
power of 1
0
25 24 23 22 21 20 0
2: 0
1 7
CSC 1303 Midterm Study Guide
1  
0 Two’s binary notion with 6
2
1
1 bits.
0
1 21 = 21/2=10 R=1
10/2=5 R 0
1
0 5/2=2 R 1
2
1
2 2/2 =1 R 0 Please complete the
1
0
½=0 R 1 following operations in
Ans= 010101 2’s complements:
1
0 0= 000000 7 – 12 =
2
1000101
1
3
1
1 -1 1001
complement 000110
1
add 1 111011 12 001100
1
0
2
4
-1 = 111111 -7 111001 -- to get this,
0
0
-10 001010 invert all bits of 7
complement 110101 (000111) and add 1
1 add 1
1
0 25
-10 = 110110
----------
0
1
5 1000101
1
1
0
1
0
26

By using of 8 bits, please 123 + 5 =


convert decimal to
123 0010111
1

binary, binary to decimal


1
0 27

+5 101 -- to get
1

for the following values:


1

1 this, invert all bits of 123


1
1 28
(0010111)
100011
0
0
35 = 128 11100
1

10111
1
Divide
1
0
29
35 1 23 =
1
by 2
Divide
1
23
17 1 1 P,q,r Boolean Variables with
by 2
1
1 30 \ ones and zeros
1
0 11 1
8 0 [(p ∨ q)

q r q∨ P xor A
∧ (p → r)

1 ∼r
q
1
5 1 ∼r L
1
1
31
4 0
1 L
2 0 0 0 1 1 0 1 0
1
0 2 0
0
32
0 0 1 0 0 0 0 0
0
1 1
0
1 1
1
0
0
-43 =- 101011 1 0 1 1 1 1 1
0
0
64
Divide 43 1 1 1 0 1 1 0 0
0
by 2
0

0 0 1 1 1 1 0
21 1
1
0
0
0 12
-27 = -11011 0 1 0 0 1 0 0
0
0
8
10 0
Divide
0 27 1 1 0 1 1
0
0 1 0
by 2 5 1
1
0 13 1 1 1 0 1 0 0 0
0
0
25
0
0
6 2 0
0
0
6 0
0

1 1
3 1

1 1
CSC 1303 Midterm Study Guide
Unicode system Then 536247 =
patterns up to 21 bits Names and identifiers
1334610. You must give your
to represent the Convert 1334610 to the program a name.
symbols uses in corresponding base-seven
language worldwide. number. public class GangstaRap {
UTF-32 represents each
21-bit code point value as  
Naming convention:
a single 32-bit code unit. capitalize each word (e.g.
(In Unicode, code points MyClassName)
are 21-bit integers). UTF- Your program's file must
32 is optimized for systems match exactly
where 32-bit values are (GangstaRap.java)
easier or faster to process includes capitalization
and space is not an issue. It (Java is "case-sensitive")
is popular where memory identifier: A name given
space is of little concern, to an item in your program.
When I got to that "5" on top,
but fixed width, single must start with a letter or
code unit access to I had to stop, because 7 can't _ or $
characters is desired. divide into 5. subsequent characters can
be any of those or a
number
Then 1334610 = 536247.
Convert 536247 to the legal:
corresponding decimal Java Chapter _myName
TheCure
number.
1&2 ANSWER_IS_42
A Java program $bling$
public class Hello { illegal:
digits:  5 3 6 2 4
public static void me+u
numbering:  4 3 2 1 0 main(String[] args) { 49ers
side-swipe
System.out.println("Hello, Ph.D's
Then I'll do the multiplication
world!");
and addition: System.out.println(); Keywords
keyword: An identifier that
System.out.println("This you cannot use because it
5×74 + 3×73 + 6×72 + 2×71 +
program produces"); already has a reserved
4×70 meaning in Java.
System.out.println("four
= 5×2401 + 3×343 + 6×49 + lines of output"); abstract default if
} private this
2×7 + 4×1 boolean do
}
Its output: implements protected
= 12005 + 1029 + 294 + 14 + 4 Hello, world! throw
This program produces
= 13346 four lines of output
CSC 1303 Midterm Study Guide
break double compiler to string: A sequence of
import public fail. characters to be printed.
throws – Missing Starts and ends with a "
byte else semicolon quote " character.
instanceof return – Too many The quotes do not appear
transient or too few { in the output.
case extends int } braces
short try – Illegal Examples:
catch final identifier
interface static void for class "hello"
char finally long name "This is a string. It's very
strictfp volatile – Class and long!"
class float native file names
super while do not Restrictions:
const for new match May not span multiple
switch lines.
continue goto Syntax error
package synchronized example "This is not
1 public class Hello { a legal String."
syntax: The set of legal 2 pooblic static void
structures and commands main(String[] args) { May not contain a "
that can be used in a 3 character.
particular language. System.owt.println("Hello,
– Every basic world!")_ "This is not a "legal"
Java 4 } String either."
statement 5 }
ends with a Escape sequences
semicolon ; Compiler output: A special sequence of
– The characters used to
contents of Hello.java:2: <identifier> represent certain special
a class or expected characters in a string.
method pooblic static void
occur main(String[] args) { \t tab character
between ^ \n new line
{ and } Hello.java:3: ';' expected character
– syntax } \" quotation
error ^ mark character
(compiler 2 errors \\ backslash
error): A character
problem in The compiler shows the
the structure line number where it found Example:
of a the error. System.out.println("\\hello\
program The error messages can be nhow\tare \"you\"?\\\\");
that causes tough to understand!
the
CSC 1303 Midterm Study Guide
Output: System.out.println(3 * 4);
\hello System.out.println("This is prints 12
how are "you"?\\ message2.");
message1();
Questions
What is the output of the System.out.println("Done
following println with message2.");
statements? }
}
System.out.println("\ta\tb\t
c"); Output:
System.out.println("\\\\"); This is message1.
System.out.println("'"); This is message2.
System.out.println("\"\"\"") This is message1. The % operator computes
; Done with message2. the remainder from integer
System.out.println("C:\nin\ Done with main. division.
the downward spiral"); 14 % 4 is 2
Expressions 218 % 5 is 3
expression: A value or
Write a println statement to operation that computes a Applications of %
produce this output: value. operator:
Obtain last digit of a
/ \ // \\ /// \\\ Examples: 1 + 4 * 5 number:
(7 + 2) * 6 / 3 230857 % 10 is 7
Methods calling methods 42 Obtain last 4 digits:
public class 658236489 % 10000 is
MethodsExample { Arithmetic operators 6489
public static void operator: Combines See whether a number is
main(String[] args) { multiple values or odd: 7 % 2 is 1
message1(); expressions. 42 % 2 is 0
message2();
+ addition precedence: Order in
System.out.println("Done - subtraction (or which operators are
with main."); negation) evaluated.
} * multiplication Generally operators
/ division evaluate left-to-right.
public static void % modulus (a.k.a. 1 - 2 - 3 is (1 - 2) - 3
message1() { remainder) which is -4
System.out.println("This is But * / % have a higher
message1."); As a program runs, its level of precedence than +
} expressions are -
evaluated. 1+3*4 is 13
public static void 1 + 1 evaluates to 2 6+8/2*3
message2() { 6+ 4 *3
6 + 12 is 18
CSC 1303 Midterm Study Guide
6*3-9/4
Parentheses can force a (5 - 7) * 4 What is the decimal equivalent of
each of the following binary
certain order of evaluation: 6 + (18 % (17 - 12)) numbers?
(1 + 3) * 4 is 16 a. 100
Answers: b. 1011
c. 101010
Spacing does not affect 1 d. 1001110
order of evaluation 15 a. 100 = 4
1+3 * 4-2 is 11 37 b. 1011 = 11
47 c. 101010 = 42
• 1*2+3*5%4 9 d. 1001110 = 78
• \_/ 16
| -8 Which of the following
2 +3*5%4 9 can be used in a Java
• \_/ program as identifiers?
| Real Numbers println first-name
2 + 15 % 4 2.0 * 2.4 + 2.25 * 4.0 / 2.0 AnnualSalary "hello" ABC
• \___/ \___/ 42isTheAnswer for
| | sum_of_data _average B4
2 + 3 4.8 + 2.25 * 4.0 / 2.0
• \________/ \___/ The legal identifiers shown
| | are println, AnnualSalary,
5 4.8 + 9.0 / 2.0 ABC, sum_of_data,
\_____/ _average, and B4
1+8%3*2-9 |
\_/ 4.8 + 4.5 What is the output
| \____________/ produced from the
1+ 2 *2-9 | following statements?
\___/ 9.3 System.out.println("\"Quot
| es\"");
1+ 4 -9 On the test System.out.println("Slashe
\______/ s \\//");
| 2. Convert each of the System.out.println("How
5 -9 following decimal '\"confounding' \"\\\" it
\_________/ numbers into its is!");
| equivalent binary
-4 number: "Quotes"
a. 6 Slashes \//
What values result from b. 44 How '"confounding' "\"
the following c. 72 it is!
expressions? d. 131
What is the output
9/5 a. 6 = 110 produced from the
695 % 20 b. 44 = 101100 following statements?
7+6*5 c. 72 = 1001000 System.out.println("name\t
7*6+5 d. 131 = 10000011 age\theight");
248 % 100 / 5
CSC 1303 Midterm Study Guide
System.out.println("Archie in he downward spiral ''quotes.''
\t17\t5'9\""); 14. Write a println
System.out.println("Betty\t 11. What is the output statement that produces the
17\t5'6\""); produced from the following output:
System.out.println("Jughea following statements? / \ // \\ /// \\\
d\t16\t6'"); System.out.println("Dear
\"DoubleSlash\" System.out.println("\"Se
name age height magazine,"); veral slashes are
Archie 17 5'9" System.out.println(); sometimes seen,\"");
Betty 17 5'6" System.out.println("\tYour System.out.println("said
Jughead 16 6' publication confuses me. Is Sally. \"I've said so.\"
it"); See?");
System.out.println("a \\\\ System.out.println("\\ / \\
9. What is the output slash or a //// slash?"); \\ // \\\\\\ ///");
produced from the System.out.println("\nSinc
following statements? erely,"); 19. What is the output of the
following program? (You may
System.out.println("Shaq System.out.println("Susan wish to draw a structure diagram
is 7'1"); \"Suzy\" Smith"); first.)
System.out.println("The 12. What series of println 1 public class Tricky {
2 public static void main(String[] args) {
string \"\" is an empty statements would produce 3 message1();
message."); the following output? 4 message2();
5 System.out.println("Done with
System.out.println("\\'\"\"") "Several slashes are main.");
; sometimes seen," 6}
7
said Sally. "I've said so." 8 public static void message1() {
Shaq is 7'1 See? 9 System.out.println("This is
message1.");
The string "" is an empty \ / \\ // \\\ /// 10 }
message. 11
12 public static void message2() {
\'"" Dear "DoubleSlash" 13 System.out.println("This is
magazine, message2.");
14 message1();
10. What is the output Your publication 15 System.out.println("Done with
produced from the confuses me. Is it message2.");
16 }
following statements? a \\ slash or a //// slash? 17 }
System.out.println("\ta\tb\t Sincerely, This is message1.
c"); Susan "Suzy" Smith This is message2.
System.out.println("\\\\"); This is message1.
Done with message2.
System.out.println("'"); 13. What series of println Done with main.
System.out.println("\"\"\"") statements would
; produce the following 20. What is the output of the
System.out.println("C:\nin\ output? following program? (You may
wish to draw a structure diagram
the downward spiral"); This is a test of your first.)
knowledge of "quotes" 1 public class Strange {
abc used 2 public static void first() {
3 System.out.println("Inside first
\\ in 'string literals.' method");
' You're bound to "get it 4}
5
""" right" 6 public static void second() {
C: if you read the section on 7 System.out.println("Inside second
method");
CSC 1303 Midterm Study Guide
8 first(); I am method 2. 17. What is the output of
9}
10 I am method 1. the following loop?
11 public static void third() { I am method 2. int total = 25;
12 System.out.println("Inside third
method"); I am method 3. for (int number = 1;
13 first(); I am method 1. number <= (total / 2);
14 second();
15 } number++) {
16 15. Complete the code for total = total – number;
17 public static void main(String[] args)
{ the following for loop: System.out.println(total + "
18 first(); for (int i = 1; i <= 6; i++) " + number);
19 third();
20 second(); { }
21 third(); // your code here
22 }
23 } } 24 1
Inside first method so that it prints the 22 2
Inside third method
Inside first method following numbers, one 19 3
Inside second method per line: 15 4
Inside first method
Inside second method –4 10 5
Inside first method 14
Inside third method 32 18. What is the output of
Inside first method
Inside second method 50 the following loop?
Inside first method 68 System.out.println("+---
86 +");
23. What is the output of the for (int i = 1; i <= 3; i++) {
following program? (You may
wish to draw a structure diagram
for (int i = 1; i <= 6; i++) System.out.println("\\ /");
first.) { System.out.println("/ \\");
1 public class Confusing { // your code here }
2 public static void method2() {
3 method1(); System.out.println(18 * i System.out.println("+---
4 System.out.println("I am method 2."); 22) +");
5}
6 ;
7 public static void method3() { } ++
8 method2();
9 System.out.println("I am method 3."); \/
10 method1(); /\
11 }
12 16. What is the output of \/
13 public static void method1() { the following oddStuff /\
14 System.out.println("I am method 1.");
15 } method? \/
16 public static void /\
17 public static void main(String[] args)
{ oddStuff() { 19. What is the output of
18 method1(); int number = 4; the following loop?
19 method3();
20 method2(); for (int count = 1; count <= for (int i = 1; i <= 3; i++)
21 method3(); number; count++) { System.out.println("How
22 }
23 } System.out.println(number many lines");
I am method 1. ); System.out.println("are
I am method 1. number = number / 2; printed?");
I am method 2.
I am method 3. } How many lines
I am method 1. 4 How many lines
I am method 1. 2 How many lines
CSC 1303 Midterm Study Guide
are printed? 4 8 12 16 20 24 28 32 36 25. What is the output of
20. What is the output of 40 the following sequence of
the following loop? 5 10 15 20 25 30 35 40 45 loops? Notice that the
System.out.print("T-minus 50 code is the same as that
"); 23. What is the output of in the previous exercise,
for (int i = 5; i >= 1; i——) the following sequence of except that the placement
{ loops? of the braces has
System.out.print(i + ", "); for (int i = 1; i <= 2; i++) { changed.
} for (int j = 1; j <= 3; j++) { for (int i = 1; i <= 2; i++) {
System.out.println("Blasto for (int k = 1; k <= 4; k++) for (int j = 1; j <= 3; j++) {
ff!"); { for (int k = 1; k <= 4; k++)
System.out.print("*"); {
Tminus } System.out.print("*");
5, 4, 3, 2, 1, Blastoff! System.out.print("!"); System.out.print("!");
} }
21. What is the output of System.out.println(); System.out.println();
the following sequence of } }
loops? * }
for (int i = 1; i <= 5; i++) { *** ************!
for (int j = 1; j <= 10; j++) ***** ************!
{ *******
System.out.print((i * j) + " *********
"); ***********
} *************
System.out.println(); ***************
} *****************
22. What is the output of *******************
the following sequence of 24. What is the output of
loops? the following sequence of
for (int i = 1; i <= 10; i++) loops? Notice that the
{ code is the same as that
for (int j = 1; j <= 10 — i; in the previous exercise,
j++) { except that the placement
System.out.print(" "); of the braces has changed.
} for (int i = 1; i <= 2; i++) {
for (int j = 1; j <= 2 * i — for (int j = 1; j <= 3; j++) {
1; j++) { for (int k = 1; k <= 4; k++)
System.out.print("*"); {
} System.out.print("*");
System.out.println(); }
} }
System.out.print("!");
1 2 3 4 5 6 7 8 9 10 System.out.println();
2 4 6 8 10 12 14 16 18 20 }
3 6 9 12 15 18 21 24 27 30 ****!****!****!
****!****!****!

You might also like