Mastering Javascript operators JAVASCRIPT OPERATORS BITWISE OPERATORS AND WHAT THEY DO USING TRACE TABLES TO PREDICT OUTPUT.

Slides:



Advertisements
Similar presentations
By: Matthew Ng. AND, XOR, OR, Complement, Circular Left shift, and Addition Modulo Circular Left Shift is done with s positions (0 ≤ s ≤ 31) – Denoted.
Advertisements

Number Bases Informatics INFO I101 February 9, 2004 John C. Paolillo, Instructor.
The Binary Numbering Systems
First project Create a JApplet with 3 textfields (2 for input and one for the answer), appropriate labels, and buttons for plus, minus and times. Your.
Advanced Topics Object-Oriented Programming Using C++ Second Edition 13.
Chapter 4 Operations on Bits
More on Numerical Computation CS-2301 B-term More on Numerical Computation CS-2301, System Programming for Non-majors (Slides include materials from.
1 COMP541 Arithmetic Circuits Montek Singh Mar 20, 2007.
CS 3850 Lecture 5 Operators. 5.1 Binary Arithmetic Operators Binary arithmetic operators operate on two operands. Register and net (wire) operands are.
Combinational Comparators
CSCE 211: Digital Logic Design Chin-Tser Huang University of South Carolina.
More about Numerical Computation CS-2301, B-Term More about Numerical Computation CS-2301, System Programming for Non-Majors (Slides include materials.
Bit Operations C is well suited to system programming because it contains operators that can manipulate data at the bit level –Example: The Internet requires.
A bit can have one of two values: 0 or 1. The C language provides four operators that can be used to perform bitwise operations on the individual bits.
Professor Jennifer Rexford COS 217
Binary Operations Math/Logical. Binary Math Decimal Addition Example ) Add = 15 Write down 5, carry ) Add 3 +
Compunet Corporation1 Programming with Visual Basic.NET Arithmetic, Logical & Bitwise Operators Week # 3 Tariq Ibn Aziz.
ENGIN112 L3: More Number Systems September 8, 2003 ENGIN 112 Intro to Electrical and Computer Engineering Lecture 3 More Number Systems.
Key Stone Problems… Key Stone Problems… next © 2007 Herbert I. Gross Set 12.
Binary Conversion In today’s lesson we will link together the binary and algorithm topics by looking at how to get the computer to: convert binary to decimal.
Building Adders & Sub tractors Dr Ahmed Telba. Introducing adder circuits Adder circuits are essential inside microprocessors as part of the ALU, or arithmetic.
Game Programming © Wiley Publishing All Rights Reserved. The L Line The Express Line to Learning L Line L.
Positional Number Systems
4. Python - Basic Operators
Logic and data representation Revision. AND gate A B A B All inputs have to be true ( i.e 1) for the output of the gate to be high, in all other cases.
Click to edit Master title style Click to edit Master text styles –Second level Third level –Fourth level »Fifth level 1 Today’s Topics How information.
Computer Sensing and Control How is binary related to what we are trying to accomplish in electronics? The PC GadgetMaster II uses binary to communicate.
 Input and Output Functions Input and Output Functions  OperatorsOperators Arithmetic Operators Assignment Operators Relational Operators Logical Operators.
1 Programming in Machine Language SCSC 311 Spring 2011.
Mastering Char to ASCII AND DOING MORE RELATED STRING MANIPULATION Why VB.Net ?  The Language resembles Pseudocode - good for teaching and learning fundamentals.
1 The Chinese University of Hong Kong Faculty of Education Diploma in Education (Part-Time) Winter 1997 Educational Communications and Technology Assignment.
1 CS103 Guest Lecture Number Systems & Conversion Bitwise Logic Operations.
Basic Operators. What is an operator? using expression is equal to 9. Here, 4 and 5 are called operands and + is the operator Python language supports.
CSC 270 – Survey of Programming Languages C Lecture 5 – Bitwise Operations and Operations Miscellany.
Logic (continuation) Boolean Logic and Bit Operations.
CSCI 2910 Client/Server-Side Programming
1 Recap lecture 21 Example of Moore machine, Mealy machine, Examples, complementing machine, Incrementing machine.
UniMAP Sem2-10/11 DKT121: Fundamental of Computer Programming1 Number Systems and Bitwise Operation.
CSE 351 Number Representation & Operators Section 2 October 8, 2015.
Module 5 JavaScript Operators. CS346 Javascript-52 Examples  JS-5 Examples.
Lecture # 15. Mealy machine A Mealy machine consists of the following 1. A finite set of states q 0, q 1, q 2, … where q 0 is the initial state. 2. An.
CSE 351 Number Representation. Number Bases Any numerical value can be represented as a linear combination of powers of n, where n is an integer greater.
Department of Electronic & Electrical Engineering Expressions operators operands precedence associativity types.
Numerical formats What’s the main idea? Want to represent numbers (eg: 45, -12, ) using only bits. We’ve already seen (or you can read in the book)
Computing Systems Lecture 3 Binary Representation & Boolean Logic Binary and Logic 1.
Computer Engineering page 1 Integer arithmetic Depends what you mean by “integer”. Assume at 3-bit string. –Then we define: zero = 000 one = 001 Use zero,
Windows Programming Lecture 06. Data Types Classification Data types are classified in two categories that is, – those data types which stores decimal.
OPERATORS IN C CHAPTER 3. Expressions can be built up from literals, variables and operators. The operators define how the variables and literals in the.
Number Systems. The position of each digit in a weighted number system is assigned a weight based on the base or radix of the system. The radix of decimal.
Arithmetic Circuits I. 2 Iterative Combinational Circuits Like a hierachy, except functional blocks per bit.
CMSC 202 Lesson 26 Miscellaneous Topics. Warmup Decide which of the following are legal statements: int a = 7; const int b = 6; int * const p1 = & a;
COMPUTER ORGANIZATION 4 TH LECTURE. ASCII Code  ASCII ( American Standard Code for Information Interchange).  Input and output devices that communicate.
Combinational Circuits
Chapter 4 Operations on Bits.
CS/COE 0447 (term 2181) Jarrett Billingsley
A Level Computing Component 2
Number Systems and Bitwise Operation
CMSC201 Computer Science I for Majors Lecture 03 – Operators
Operators and Expressions
Topic 3: Data Binary Arithmetic.
CISC101 Reminders Your group name in onQ is your grader’s name.
More about Numerical Computation
CS 240 – Lecture 9 Bit Shift Operations, Assignment Expressions, Modulo Operator, Converting Numeric Types to Strings.
Fundamentals of Data Representation
A-level Computer Science
Combinational Circuits
Bitwise Operators.
Numbers and Arithmetic and Logical Operation
靜夜思 床前明月光, 疑是地上霜。 舉頭望明月, 低頭思故鄉。 ~ 李白 李商隱.
Programming Techniques :: Arithmetic & Boolean Operators
Presentation transcript:

Mastering Javascript operators JAVASCRIPT OPERATORS BITWISE OPERATORS AND WHAT THEY DO USING TRACE TABLES TO PREDICT OUTPUT

Did you know? It was developed as a language in just 10 days! JavaScript was originally developed by Brendan Eich, while he was working for Netscape Communications Corporation Although it was developed under the name Mocha, the language was officially called LiveScript when it first shipped in beta releases of Netscape Navigator 2.0 in September 1995, but it was renamed JavaScript Eich also co-founded the Mozilla project, with a website at mozilla.org.

Game development and Javascript The game is pure JavaScript & XHTML. There is a nice use of CSS sprites in this particular game implementation.

Game development and Javascript A RPG engine written in Javascript that has items to be picked, monsters & more.

Game development and Javascript …and of course there is MINECRAFT. You might be interested in the following link if you’re interested in programming in Minecraft …and of course there is MINECRAFT. You might be interested in the following link if you’re interested in programming in Minecraft

Predict the output ? ? MooseYOUTPUT That was easy enough – let’s try another one

Using trace tables Trace tables help you to predict the output using a structured method The first thing you need to do is list all the variables in the columns Trace the code and fill in the values for the variables as you go along a a b b c c output

Making a note of key terms Line 6 contains an operation, namely that c is being given the new value of a+b In this case, a and b are the operands, in other words the values being operated on The plus sign (+) is the operator X * Y X and Y are the? And the * is the: operands operator

Predict the output ? ? MooseYX Output = 6 Again, quite straightforward. A harder one now.

Here we are using MOD. Predict output! MooseGooseOutput Moose = 10 MOD 6 10 MOD 6 basically checks to see if 6 goes into 10 and gives the remainder. In this case Moose = 4 (the remainder is 4) Output = 4

Try another MOD prediction: MooseGooseOutput Moose = 32 MOD 8 32 MOD 8 checks to see if 8 goes into 32 and gives the remainder. In this case there is no remainder because 8 goes perfectly into 32 Output = 0

Use of the = assignment operator MooseGooseOutput It would be useful for you to note that the = sign can also be used in a different way (as a checking for equivalence (comparison). In this case however, it is an assignment operator

What’s happening here? Try this yourself and you’ll notice something peculiar 3 3 The aim of the program is to produce an output of moose ONLY if moose = goose (they are not equal in this case) You’ll notice the output for this program is 3 (which isn’t what you expect). What is the problem? The wrong operator was used! In JavaScript the “ = = “ is the equal to operator Notice the double equals sign!

Working with bitwise operators

You may need a pen to work this one out! ? ? MooseYOutput? ? ? We need to know what the <<= operator does.

Predict the output We know that in “Moose+y”, the + operator is adding the value of Moose to y What does the <<= operator do to y?

The left shift operator <<= MooseYOutput? ? ? 1. The binary value of moose is being shifted to the left by y (shifting in zeroes from the right) 2. The operator is called the left shift bitwise operator

The left shift operator <<= MooseYOutput? Shifts moose in binary representation y (< y) bits to the left, shifting in zeroes from the right.

The left shift operator <<= MooseYOutput? First convert Moose (3) to Binary The Binary for Decimal 3 = 011 Now, apply the left shift of y. y = 2 so add 2 zeroes on from the right, to move the number along to the left

The left shift operator <<= The Binary for Decimal 3 = 011 Left shift 2 gives you: Find out what the new value is in Binary! = 12!

Change the inputs: Predict the output The Binary for Moose =1 or 01 or Left shift moose binary value = 01 by y (y = 1) 01  add one zero to the right which will shift it to the left That gives you in Binary is 2 The output is 2!

JavaScript's Operators Let’s start with the blatantly obvious operators. See if you can guess what each one does. Note that the + operator can also be used as a string operator (used to concatenate two strings together) p+ig = pig Let’s start with the blatantly obvious operators. See if you can guess what each one does. Note that the + operator can also be used as a string operator (used to concatenate two strings together) p+ig = pig ? ? ? ? ? ? ? ? ? ? ? ? ? ?

JavaScript's Assignment Operators ? ? ? ? ? ? ? ? ? ? ? ? ? ?

Comparison and logical operators ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?

JavaScript's Bitwise operators #1 OperatorUsageDescription Bitwise ANDa & b Returns a one in each bit position for which the corresponding bits of both operands are ones. Bitwise ORa | b Returns a one in each bit position for which the corresponding bits of either or both operands are ones. Bitwise And Bitwise OR

JavaScript's Bitwise operators #2 Bitwise XORa ^ b Returns a one in each bit position for which the corresponding bits of either but not both operands are ones. Bitwise NOT~ a Inverts the bits of its operand. Left shifta << b Shifts a in binary representation b (< 32) bits to the left, shifting in zeroes from the right. Bitwise XOR Bitwise NOT Left Shift

JavaScript's Bitwise operators #3 Sign-propagating right shift a >> b Shifts a in binary representation b (< 32) bits to the right, discarding bits shifted off. Zero-fill right shifta >>> b Shifts a in binary representation b (< 32) bits to the right, discarding bits shifted off, and shifting in zeroes from the left. Sign propagating right shift Zero fill right shift

Try it yourself: Task Use the operators given to create your own programs. Screenshot your results with a trace table and explanation of the operator’s function.

Here we have used Dreamweaver and the SPLIT, LIVE view