Presentation is loading. Please wait.

Presentation is loading. Please wait.

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.

Similar presentations


Presentation on theme: "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."— Presentation transcript:

1 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 (2013-14) For first assessment. Students may use a calculator during the test.

2 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

3 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

4 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.

5 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.

6 The characters available

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

8 The whole picture

9 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.

10 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=“”

11 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”);

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

13 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);

14 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

15 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

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

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

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

19 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

20 Converting binary to decimal


Download ppt "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."

Similar presentations


Ads by Google