Download Prof. Rommel Anthony Palomino

Survey
yes no Was this document useful for you?
   Thank you for your participation!

* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project

Document related concepts
no text concepts found
Transcript
Introduction to Programming
<Lecture 2>
Prof. Rommel Anthony Palomino
Department of Computer Science and
Information Technology
Spring 2011
Number Systems and Conversions
 0010
23 22 21 20
0000
2
0000
0001 0010
2 01 2
Rommel AB Palomino - UDC Spring 2011
Number Systems and Conversions

Numbers can be represented in many ways

There exist many Numeral System or ways to
represent numbers.

Their representation depends on something called BASE

BASE - 1 is the maximum number you can represent
using a single digit.

3
Base 10  Max number using single digit = 10 – 1 = 9
Rommel AB Palomino - UDC Spring 2011
Number Systems and Conversions
The most well known numeral system is the Decimal
System. The one you use everyday.



Base 10
It consist of 10 elements from 0-9.
Besides decimals, there exists others such as:




4
Binary: Base 2. Uses 2 elements. 0 to 1
Octal: Base 8. Uses 8 elements. 0 to 8.
Hexadecimal: ????
Rommel AB Palomino - UDC Spring 2011
Number Systems and Conversions
Hexadecimal: Uses up to 16 digits.
From 0 to 15 ???


5
Hex
Dec
0
0
1
1
2
2
3
3
…
…
9
9
A
10
B
11
C
12
D
13
E
14
F
15
Rommel AB Palomino - UDC Spring 2011
Number Systems and Conversions
Hexadecimal: Uses up to 16 digits.
From 0 to 15 ???


FF16 = 25510
6
Hex
Dec
0
0
1
1
2
2
3
3
…
…
9
9
A
10
B
11
C
12
D
13
E
14
F
15
Rommel AB Palomino - UDC Spring 2011
Conversion: Decimal to Binary
Method:








7
Continuously divide the number by 2
get the remainder (which is either 0 or 1)
get that number as a digit of the binary form of the number
get the quotient and divide that number again by 2
repeat the whole process until the quotient reaches 0 or 1
we then get all the remainders starting from the last remainder,
and the result is the binary form of the number
NOTE: For the last digit which is already less than the divisor
(which is 2) just copy the value to the remainder portion.
Rommel AB Palomino - UDC Spring 2011
Conversion: Decimal to Binary
Example


Convert 15010 to Binary
Number
Base
Quotient
Remainder
150
2
75
0
75
2
37
1
37
2
18
1
18
2
9
0
9
2
4
1
4
2
2
0
2
2
1
0
1
2
0
1
Solution: 10010110 = 150

8
Rommel AB Palomino - UDC Spring 2011
Conversion: Binary to Decimal
Method:



9
we multiply the binary digit to "2 raised to the position of the
binary number"
We then add all the products to get the resulting decimal
number.
Rommel AB Palomino - UDC Spring 2011
Conversion: Binary to Decimal

Example
Convert 111001012 to Decimal
0: 1
2: 4
5: 32
6: 64
7: 128


Solution: 229
10
Rommel AB Palomino - UDC Spring 2011
Conversion: Binary to Hexadecimal

Method:



11
Partition the binary number into groups of 4 digits (from right
to left)
pad it with zeros if the number of digits is not divisible by 4
convert each partition into its corresponding hexadecimal
digit
Rommel AB Palomino - UDC Spring 2011
Conversion: Binary to Hexadecimal

Example


Convert 111001012 to Hexadecimal
Solution:
12
Rommel AB Palomino - UDC Spring 2011
Programming Fundamentals
13
Rommel AB Palomino - UDC Spring 2011
Introduction to Java

The original motivation for Java

14
The need for platform independent language that could be
embedded in various consumer electronic products.
Rommel AB Palomino - UDC Spring 2011
Introduction to Java

The Java technology is:




15
A programming language
A development environment
An application environment
A deployment environment
Rommel AB Palomino - UDC Spring 2011
Introduction to Java

As a development environment, Java technology provides
you with a large suite of tools:



16
A compiler
An interpreter
A documentation generator, etc
Rommel AB Palomino - UDC Spring 2011
Java Features

Some features of Java:



17
The Java Virtual Machine
Bytecode
Garbage Collection
Rommel AB Palomino - UDC Spring 2011
Java Features

Java Virtual Machine (JVM)


18
an imaginary machine that is implemented by emulating
software on a real machine
provides the hardware platform specifications to which you
compile all Java technology code
Rommel AB Palomino - UDC Spring 2011
Java Features

Bytecode


19
a special machine language that can be understood by the Java
Virtual Machine (JVM)
independent of any particular computer hardware, so any
computer with a Java interpreter can execute the compiled
Java program, no matter what type of computer the program
was compiled on
Rommel AB Palomino - UDC Spring 2011
Java Features

Garbage collection thread


20
responsible for freeing any memory that can be freed. This
happens automatically during the lifetime of the Java program.
programmer is freed from the burden of having to deallocate
that memory themselves
Rommel AB Palomino - UDC Spring 2011
How a Java Program works?
21
Rommel AB Palomino - UDC Spring 2011
Exercise

Write a flowchart for

22
How to answer and end a phone call in your Cellphone
Rommel AB Palomino - UDC Spring 2011
Questions?
23
Rommel AB Palomino - UDC Spring 2011
For Next Class

We will do our first Java Program and will learn how to
use our Programming Environment
24
Rommel AB Palomino - UDC Spring 2011