left shift operator in python example

Example 1: and operator in javascript

//&& returns true if both values are true
//or returns the second argument if the first is true
var a = true
var b = ""
var c = 1

true && "" //""
"" && 1 //""
false && 5 //false

Example 2: write a program to input a number and display its double and half values using shift operator in python

# Write a program to input a number and display its Double and Half values using SHIFT operator

print("Hi \nThis is a basic calculator \nwhich doubles or divides into half the value entered in it")
a = int(input("pls enter your number:\n"))
b = a << 1
c = a >> 1
print("number:", a, "\ndouble:", b, "\nhalf:", c)

Example 3: left shift in java

int a=a<<n;
//where n is the number of places a is shifted towards left.

Tags: