What is Binary Code? Computers use a special code of their own to express the digital information they process. It's called the binary code because it.

Slides:



Advertisements
Similar presentations
Introduction to Computers Part II
Advertisements

AP Computer Science Anthony Keen. Computer 101 What happens when you turn a computer on? –BIOS tries to start a system loader –A system loader tries to.
Base Conversion COP Practice Problem  Print a String in reverse order:  For example, if we want to print “HELLO” backwards,  we first print:
Chapter 7 Strings F To process strings using the String class, the StringBuffer class, and the StringTokenizer class. F To use the String class to process.
Primitive Data Types There are a number of common objects we encounter and are treated specially by almost any programming language These are called basic.
Data Types in Java Data is the information that a program has to work with. Data is of different types. The type of a piece of data tells Java what can.
Week 2: Primitive Data Types 1.  Programming in Java  Everything goes inside a class  The main() method is the starting point for executing instructions.
CIS 234: Using Data in Java Thanks to Dr. Ralph D. Westfall.
Aalborg Media Lab 21-Jun-15 Software Design Lecture 2 “ Data and Expressions”
Introduction to Computers and Programming Lecture 5 Boolean type; if statement Professor: Evan Korth New York University.
Binary Expression Numbers & Text CS 105 Binary Representation At the fundamental hardware level, a modern computer can only distinguish between two values,
ECE122 L3: Expression Evaluation February 6, 2007 ECE 122 Engineering Problem Solving with Java Lecture 3 Expression Evaluation and Program Interaction.
1 Data types, operations, and expressions Overview l Format of a Java Application l Primitive Data Types l Variable Declaration l Arithmetic Operations.
The UNIVERSITY of NORTH CAROLINA at CHAPEL HILL Adrian Ilie COMP 14 Introduction to Programming Adrian Ilie June 27, 2005.
CSci 142 Data and Expressions. 2  Topics  Strings  Primitive data types  Using variables and constants  Expressions and operator precedence  Data.
String Escape Sequences
Computer Fluency Binary Systems. Humans Decimal Numbers (base 10) Decimal Numbers (base 10) Sign-Magnitude (-324) Sign-Magnitude (-324) Decimal Fractions.
Bits and Bytes.
Data vs. Information OUTPUTOUTPUT Information Data PROCESSPROCESS INPUTINPUT There are 10 types of people in this world those who read binary and those.
1 Survey of Computer Science CSCI 110, Spring 2011 Lecture 16 Digital Circuits, binary Numbers.
1 Variables, Constants, and Data Types Primitive Data Types Variables, Initialization, and Assignment Constants Characters Strings Reading for this class:
MATH 224 – Discrete Mathematics
Programming for Artists ART 315 Dr. J. R. Parker Art/Digital Media Lab Lec 10 Fall 2010.
General Computer Science for Engineers CISC 106 Lecture 02 Dr. John Cavazos Computer and Information Sciences 09/03/2010.
Data Representation S2. This unit covers how the computer represents- Numbers Text Graphics Control.
Foundations of Computer Science Computing …it is all about Data Representation, Storage, Processing, and Communication of Data 10/4/20151CS 112 – Foundations.
Binary Code.
The string data type String. String (in general) A string is a sequence of characters enclosed between the double quotes "..." Example: Each character.
Input, Output, and Processing
5 BASIC CONCEPTS OF ANY PROGRAMMING LANGUAGE Let’s get started …
CIS 260: App Dev I. 2 Programs and Programming n Program  A sequence of steps designed to accomplish a task n Program design  A detailed _____ for implementing.
Lecture 2: Introduction to C Programming. OBJECTIVES In this lecture you will learn:  To use simple input and output statements.  The fundamental data.
Programming for Beginners Martin Nelson Elizabeth FitzGerald Lecture 2: Variables & Data Types.
1 Data Representation Characters, Integers and Real Numbers Binary Number System Octal Number System Hexadecimal Number System Powered by DeSiaMore.
PHY-102 SAPVariables and OperatorsSlide 1 Variables and Operators In this section we will learn how about variables in Java and basic operations one can.
1 Ethics of Computing MONT 113G, Spring 2012 Session 1 Digital Circuits, binary Numbers Course webpage:
Programming with Visual C++: Concepts and Projects Chapter 3A: Integral Data (Concepts)
Data Representation (in computer system). Data Representation How do computers represent data? b The computers are digital Recognize.
A Simple Java Program //This program prints Welcome to Java! public class Welcome { public static void main(String[] args) { public static void main(String[]
INFORMATION TECHNOLOGY
School of Computer Science & Information Technology G6DICP - Lecture 4 Variables, data types & decision making.
Programming in Java (COP 2250) Lecture 4 Chengyong Yang Fall, 2005.
Operators and Expressions. 2 String Concatenation  The plus operator (+) is also used for arithmetic addition  The function that the + operator performs.
CSC 1010 Programming for All Lecture 3 Useful Python Elements for Designing Programs Some material based on material from Marty Stepp, Instructor, University.
Structured Programming (4 Credits) HNDIT Week 2 – Learning Outcomes Design an algorithmic solution for simple problem such as computation of a factorial,
Exploring Computer Science – Lesson 2-5. Click to add text.
COMP 110: Spring Announcements Lab 1 due Wednesday at Noon Assignment 1 available on website Online drop date is today.
© 2007 Pearson Addison-Wesley. All rights reserved2-1 Character Strings A string of characters can be represented as a string literal by putting double.
Expressions and Order of Operations Operators – There are the standard operators: add, subtract, divide, multiply – Note that * means multiply? (No times.
CS 106 Introduction to Computer Science I 09 / 10 / 2007 Instructor: Michael Eckmann.
09/06/ Data Representation ASCII, Binary Denary Conversion, Integer & Boolean data types.
Lecture 3: More Java Basics Michael Hsu CSULA. Recall From Lecture Two  Write a basic program in Java  The process of writing, compiling, and running.
 Human language : commonly used to express feeling and understand what other people expression.  Computer language : are a languages by which a user.
© 2004 Pearson Addison-Wesley. All rights reserved August 27, 2007 Primitive Data Types ComS 207: Programming I (in Java) Iowa State University, FALL 2007.
CS 106A, Lecture 4 Introduction to Java
Exploring Computer Science – Lesson 2-5
3.1 Denary, Binary and Hexadecimal Number Systems
Visual Basic 6 (VB6) Data Types, And Operators
Binary Number System Lesson objectives:
Information Technology Introduction to Number System
Primitive Data Types August 28, 2006 ComS 207: Programming I (in Java)
Representation of data in computer systems
Multiple variables can be created in one declaration
Number Systems.
Escape Sequences What if we wanted to print the quote character?
1) C program development 2) Selection structure
Chapter Four Data Representation in Computers By Bezawit E.
Primitive Types and Expressions
WJEC GCSE Computer Science
COMPUTING.
Presentation transcript:

What is Binary Code? Computers use a special code of their own to express the digital information they process. It's called the binary code because it consists of only two symbols—0s and 1s. (The "bi" in "binary" means two.) Grade 12 - Term 2 Week 1,2,3 ( ) For first assessment. Students may use a calculator during the test.

Why does the computer use 0’s and 1’s? Because those are the only two numbers you need to express the flow of electricity through a transistor. Electricity can have two states, either on or off. On is 1, off is 0. Everything you say to a computer has to be put in terms of these two numbers. Grade 12 - Term 2 Week 1,2,3 For first assessment

What do you call one of these 0s or 1s? These are referred to as a “bit”. Which makes sense when you see how many of these bits it takes to represent a word, number, color, graphic or sound. A byte consists of 8 bits. A Kilobyte consists of 1024 bytes A Megabyte consists of 1024 Kilobytes

Counting in Binary The binary system that computers use to store and process information is a base 2 system. It needs only two symbols, 0 & 1. The decimal system, however, is referred to as base 10 system. It has 10 symbols (0, 1, 2, 3, 4, 5, 6, 7, 8, 9) and is equal to the number of fingers on both our hands.

What is Morse code? Morse code is a method of transmitting text information by using a series of on – off tones, lights or clicks. Each character is represented by a unique sequence of dots and dashes. The J-38, straight key was manufactured in large quantities during world war 2 for transmitting messages.

The characters available

How to convert from Decimal to binary: Divide by 2 and write the remainder.

The whole picture

Using the mod operator for getting remainder Using the mod operator (%) you can get the remainder. Store it in a integer type variable. Add it to a string type variable by using concatenation.

String type data type String data type can contain both numbers and characters. For e.g. String myAddress=“24 Mirdiff” A new String must always be initialized. For e.g. String myNum=“”

If condition The “if” control structure can be used to check a condition being true or false For e.g. if (number>0) { println(“The speed has increased”);

Using concatenation to join String String myAddress=“24 Shouk, Mirdiff” myAddress=myAddress + ”, UAE” OUTPUT: 24 Shouk, Mirdiff, UAE

Java code for binary to decimal conversion public void run() { String myNum=""; // Initializing the String variable int r; // This will store the remander int i = readInt("Please enter a number"); while (i>0) { r = i%2; if (r>0) { myNum=myNum+"1"; } else myNum=myNum+"0"; i=i/2; } println(myNum);

Printing a String in reverse 1.Count the length of the String 2.Run a definite loop starting from length of String - 1 up to 1 3.For each cycle print a character

Two new methods.charAt: Used to return a specified character from a String.length: Returns the total number of characters in a String Both these methods belong to the String family

.charAt() Example: We want to print the 3 rd character from the word HELLO. String myWord=“HELLO”; println( myWord.charAt(3) ); OUTPUT: L

.length() Example: How many characters in the word “World”. String myWord=“World”; println( myWord.length() ); OUTPUT: 5

Java Code for reversing String for (int n=myNumber.length()-1;n>=0;n--) { print(myNumber.charAt(n) ); }

Algorithm for Converting a number from Binary to Decimal Step 1: List the powers of 2 from right to left starting with 2 0 Step 2: Write the first binary number below the list Step 3: Draw lines, connecting each consecutive digit of the binary number to the power of two Step 4: Move through each digit and if the digit is 1 write its corresponding power next to it otherwise write 0 Step 5: Add the numbers

Converting binary to decimal