Agenda Answers for in class practice 218 Computer

  • Slides: 20
Download presentation
Agenda Answers for in class practice 2/18 Computer architecture Number systems Conversion from one

Agenda Answers for in class practice 2/18 Computer architecture Number systems Conversion from one number system to anther number system • Binary addition • •

Answers 1. Primitive type: int, double, boolean, char refernce type: class, array difference between

Answers 1. Primitive type: int, double, boolean, char refernce type: class, array difference between these two types: primitive type: simple type, one value per variable Reference type: complex data type, can have more than one variable and methods.

2. switch(letter. Grade) { case ‘A’: case ‘a’: num. Grade = 95; break; case

2. switch(letter. Grade) { case ‘A’: case ‘a’: num. Grade = 95; break; case ‘B’: case ‘b’: num. Grade = 85; break; case ‘C’: case ‘c’: num. Grade = 75; break; case ‘D’: case ‘d’: num. Grade = 65; break; default: num. Grade = 60; }

3. int players = 0; while(players < 4) { players ++; } do{ players++;

3. int players = 0; while(players < 4) { players ++; } do{ players++; }while (players<4); for(player=1; players < 4; players++);

Computer • Hardware – physical components like monitor and system unit. • Input devices

Computer • Hardware – physical components like monitor and system unit. • Input devices – keyboard, mouse, scanner, disk drive, CD-RW/DVD • Motherboard: contains expansion board CPU BUS Memory(ROM, RAM)

Input Memory CPU Output

Input Memory CPU Output

CPU • The CPU (Central Processing Unit) or processes data and controls the flow

CPU • The CPU (Central Processing Unit) or processes data and controls the flow of data between the computer’s other units. • Within the CPU is the ALU (Arithmetic Logic Unit), which can perform arithmetic and logic operations • The ALU is so fast that the time needed to carry out a single addition is measured in nanoseconds (billionths of a second). • The speed at which a CPU can execute instructions is determined by the computer’s clock rate. The clock rate is measured in megahertz(MHz, million of cycles per second) or gigahertz(GHz, billion of cycles per second).

Bus • A bus is a set of circuits that connect the CPU to

Bus • A bus is a set of circuits that connect the CPU to other components. • The data bus transfers data between the CPU, memory, and other hardware devices on the motherboard.

Memory • Memory in the form of integrated circuits (ICs) stores data electronically. •

Memory • Memory in the form of integrated circuits (ICs) stores data electronically. • ROM (Read Only Memory) contains the most basic operating instructions for the computer. The data in ROM is a permanent part of the computer and cannot be changed. • RAM (Random Access Memory), also called primary or main memory, is memory where data and instructions are stored temporarily

Number systems • The electrical circuits on an IC have one of two states,

Number systems • The electrical circuits on an IC have one of two states, off or on. Therefore, the binary number system (base 2), which uses only two digits (0 and 1), was adopted for use in computers. • To represent numbers and letters, a code was developed with eight binary digits grouped together to represent a single number or letter. Each 0 or 1 in the binary code is called a bit (Binary digi. T) and an 8 -bit unit is called a byte

Number systems • Decimal – base 10 0, 1, 2, 3, 4, 5, 6,

Number systems • Decimal – base 10 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 • Binary –base 2 0, 1 • Hexdecimal – base 16 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, A, B, C, D, E, F • Octal – base 8 0, 1, 2, 3, 4, 5, 6, 7

Convert from binary to decimal 1 0 1 0 1 6 2 5 2

Convert from binary to decimal 1 0 1 0 1 6 2 5 2 4 2 3 2 2 2 1 2 2 0 2 Þ 1 * 1 + 4 * 1 + 16 * 1 + 64 * 1 = 85

Convert from octal to decimal 1 0 4 7 8 83 82 81 80

Convert from octal to decimal 1 0 4 7 8 83 82 81 80 Þ = 1 * 7 + 8 * 4 + 512* 1 551

Convert from hex to decimal 1 E 4 A 16 163 162 161 160

Convert from hex to decimal 1 E 4 A 16 163 162 161 160 Þ 1 *10 + 16 * 4 + 256* 14 + 4096*1 = 7754

Convert from decimal to binary 2 147 1 2 73 1 2 36 0

Convert from decimal to binary 2 147 1 2 73 1 2 36 0 2 18 0 10010011 2 9 1 2 4 0 2 2 0 2 1 1

Convert decimal to hex or octal • Follow the same way to divide the

Convert decimal to hex or octal • Follow the same way to divide the numbers by 8 or by 16 and get the remainders. Remember to list the number from bottom to top. • Try to convert the following numbers to hex/octal. 147 2156

Binary additions 1 1 0 0 1 1 + 1 0 0 1 10

Binary additions 1 1 0 0 1 1 + 1 0 0 1 10 1 1 0

Binary into hex 1 0 1 1 1 2 B 7

Binary into hex 1 0 1 1 1 2 B 7

Homework • BPJ Lesson 14 all exercises. • When you do the conversion between

Homework • BPJ Lesson 14 all exercises. • When you do the conversion between different number systems, please don’t just write down the numbers, but show me the converting process, just like what we did in the class.