- Explore [has_child]
- All Courses [subitem]
- AI Career Platform [subitem]
- Hire form us [subitem]
- 1:1 Coaching/Mentoring [subitem]
- Job Board [subitem]
- Institute Partnerships [subitem]
- Resources [has_child]
- Master Classes [subitem]
- Discussion Forum [subitem]
- Coding Playground [subitem]
- Free Courses [subitem]
- Topics [has_child]
- Data Science [subitem]
- Software Development [subitem]
- Company Insights
- Interview Preparation [subitem]
- Python [subitem]
- Programming [subitem]
- Digital Marketing [subitem]
- Web Development [subitem]
- Success Stories [subitem]
Data Structures: Foundation of Effective Programming
Fundamentals of LCM and HCF-2
A Career in Digital Marketing - A Complete Guide for Beginners
Advanced Algorithms and Problem Solving Techniques
Does a Linkedin profile really matter before getting a Job?
Python Libraries
What Is Content Marketing?
Introduction to Natural Language Processing (NLP)
React Functional Components: Introduction
What is the Scope of Digital Marketing in 2025
Java Programs: Know the Best Java Programs for Beginners
What is Email Marketing in Digital Marketing?
Secrets Of A Good Resume, Which Will Get You Hired!
What is Digital Marketing & How to Become a Digital Marketer
What is Full Stack Development?
What is Consulting? Essential Insights for Aspiring Consultants
Operating System: Functions
Data Science vs. Data Analytics - What's the Difference?
Software Testing: What it is?
Why Learn English?
Discover the Versatility of Microsoft Excel: Your Swiss Army Knife for Data
Why Data Visualization is Important for Becoming a Data Scientist
What is Meant by Machine Learning & What Can Machine Learning Do?
Why Group Discussion for Interview? The HR Perspective
Encapsulation in Java: A Comprehensive Tutorial
Most Common 10 Telephonic Interview Questions
Fundas of Pandas
The Multifaceted Relationships Between Banker and Customer
Basic Guide to HTML & CSS – The Fundamentals of Web Development
Understand Serialization and Deserialization in Java
OOPs (Object Oriented Programming) in C++
Header in C++
Getting Started with Tableau: Installation and Introduction
JSON vs XML: Differences
C++ Language: An Overview
Job Trends In This Decade
Fundamentals of Divisibility Rules in Quantitative Aptitude
How To Start Your Career In Data Science
Introduction to Big Data
Step-by-Step Guide to Data Visualization with Power BI
6 Bootstrap Tools and Playground – One-stop shop for all Web Developmental Needs
Ultimate Guide to HR Interview Questions for Freshers
Software: Types & Definition
What is a Job Interview?
The Ultimate Guide to Resume building for Freshers
All About Resume and Its Importance
The Role and Importance of Banks in the Economy
Introduction to Big Data Analytics: From Basics to Implementation
What are Collections in Python?
Introduction To Cloud Computing
What are Node.js and Basics of Node.js?
A quick guide to Asymptotic Analysis
How To Start Competitive Programming - A Complete Guide
Why Social Media Marketing Is Important?
Introduction to Deep Learning: From Basics to Advanced Concepts
Introduction to Goal Setting and Risk Profiling
10 Common Data Structures Every Programmer Must Know
Types of Data in Statistics
A-Z about Python Variables
Why is it Important for Freshers to Work in a Team?
Javascript vs Typescript: What is the Difference?
What is Grooming & Etiquette?
Data Communication: A Process
Learn about Boolean in Python
Introduction to Management Interview Preparation
What is Search Engine Optimization & How It Works
Fundamentals of Digital Marketing
How to Apply for Jobs as Fresher & Get Selected in One Go
The skills required to stay relevant in IT sector
Structure of DBMS
Basics of Javascript
Mastering Vocabulary: The Key to Verbal Ability
Introduction To SQL: A Complete Guide
All about C Programming Language
Understanding the Loan Underwriting Process
The Essential SUM Function in Excel: A Step-by-Step Guide
Master Simple and Compound Interest Quickly and Accurately
Mastering SWOT Analysis for Business Success
Creating and Using Sets in Tableau: A Comprehensive Guide
System Testing: Explained
Mastering the MIN Function in Excel: Find the Lowest Value Instantly
Understanding the Difference in Simple and Compound Interest over 2 and 3 Years
Understanding Risk and Return in Mutual Funds
Mastering Value Chain Analysis: Uncovering Business Opportunities
Mastering Data Filters in Tableau: A Step-by-Step Guide
Understanding Credit Scoring Models: A Comprehensive Insight
Understanding Principle Multiplication with Compound and Simple Interest
Creating Calculated Fields in Tableau: A Step-by-Step Guide
Understanding PESTEL Analysis for Industry Evaluation
Mastering the COUNT Function in Excel
Understanding Simple Interest vs. Compound Interest
Mastering Mutual Fund Investment and Redemption Plans
Combining Data Sources Using Data Blending in Tableau
Mastering the GE-McKinsey 9-Box Matrix: A Strategic Guide
Understanding Credit Rating Agencies and Their Processes
Bringing in More Data with Joins in Tableau
Maximizing Organizational Performance with the Balanced Scorecard
Mastering the COUNTA Function in Excel
Mastering Mixtures and Alligations: Key Techniques and Practice
The Role of Financial Planning in Wealth Creation
Introduction
The left shift bitwise operator () takes two numbers and shifts the first operand's bits to the left by the amount indicated by the second operand. For instance, the expression (xy) can be used to left-shift the bits of x by y places. It is the same as dividing x by 2^y.
The following example illustrates how a left shift operator operates:
1000 << 2 returns 4000
(In Binary)
1000 -> 1111101000
<< 2 | left shift the bits
----- V by 2 places
4000 <- 111110100000
(In Binary)
Code
#include <iostream> z = x << 2; |
Output: z = 4000 |
Example: Count number of 1 Bits in a positive integer
Think of the number 1000. It can be expressed in bit-wise format as 1111101000. Not all bits, though, are written here. A 32-bit representation that is comprehensive is as follows:
00000000000000000000001111101000
When performing a bitwise AND with a 1 at any bit, the result is 1 if a bit is 1 or 0 if it is 0. The tally of 1 bits in the provided positive integer is obtained by performing such an operation on each bit and determining the number of 1s. The following example demonstrates how to use the left shift operator to achieve this goal:
#include <iostream> |
Output: CountOneBits(1000) = 6 CountOneBits(1023) = 10 |
As you can see, there is a zero in the final digit on the right and the digits have moved one position to the left. You should also be aware that moving left is the same as multiplying by two-digit powers of two. The equivalents of 6 * 2 and 6 * 8 are 6 * 1 and 6 * 3, respectively. When possible, a good optimizing compiler will switch out multiplications for shifts.
Things to Remember
- When dealing with negative numbers, you shouldn't use the left-shift or right-shift operators. If either of the inputs is a negative number, the behavior is undefinable. Answers of either 1 >> -1 and 1 -1, for instance, are undefined.
- The behavior is unknown if the number is moved by an amount greater than the size of an integer. For instance, if numbers are stored using 32 bits, 1 33 is undefined. Unsigned Long Long, which is defined using 64 bits and can hold huge quantities, 1ULL62 ULL, is used for bit shifts of larger values.
- The division of the first term and the second term raised to the power 2 and the left-shift by one are identical to the first term and the second term raised to the power 3 and the right-shift by one, respectively (1>>3 = 1/pow(2,3)).