Example of bitwise operators in c programming

Example of bitwise operators in c programming

Author: Platon On: 25.06.2017

In C, following 6 operators are bitwise operators work at bit-level. The result of AND is 1 only if both bits are 1. The result of OR is 1 any of the two bits is 1. The result of XOR is 1 if the two bits are different.

Takes two numbers, left shifts the bits of first operand, the second operand decides the number of places to shift. For example results of both -1 this for more details.

It is used in many problems.

C Bitwise Operators Examples – OR, AND, XOR, NOT, Left/Right Shift

The following are many other interesting problems which can be used using XOR operator. Find the Missing Number , swap two numbers without using a temporary variable , A Memory Efficient Doubly Linked List , and Find the two non-repeating elements. There are many more See this , this , this , this , this and this. Also, the logical operators consider any non-zero operand as 1.

As mentioned in point 1, it works only if numbers are positive. Please write comments if you find anything incorrect, or you want to share more information about the topic discussed above.

Writing code in comment? Interview Preparation Company Preparation Top Topics Placements Interview Corner Recent Interview Experiences GQ Home Page Quiz Corner LMNs Practice Platform What's New? Company-wise Problems Topic-wise Problems Subjective Problems Difficulty Level - School Difficulty Level - Basic Difficulty Level - Easy Difficulty Level - Medium Difficulty Level - Hard How to pick a difficulty level? The odd occurring element is 90 The following are many other interesting problems which can be used using XOR operator.

There are many more See this , this , this , this , this and this 3 The bitwise operators should not be used in-place of logical operators. False True 4 The left-shift and right-shift operators are equivalent to multiplication and division by 2 respectively.

Interesting facts about Operator Precedence and Associativity in C How to swap two numbers without using a temporary variable? Evaluation order of operands Print a long int in C using putchar only Find XOR of two number without using XOR operator. Load Comments Share this post!

C Bitwise Operators: AND, OR, XOR, Complement and Shift Operations

Trending Content Why is Binary Search preferred over Ternary Search? Oracle Design Patterns Set 1 Introduction Count all distinct pairs with difference equal to k. Most Visited Posts Top 10 Algorithms and Data Structures for Competitive Programming Top 10 algorithms in Interview Questions How to begin with Competitive Programming?

Step by Step Guide for Placement Preparation How to prepare for ACM-ICPC?

Insertion Sort , Binary Search , QuickSort , MergeSort , HeapSort. How to pick a difficulty level? Why is Binary Search preferred over Ternary Search? Convert array into Zig-Zag fashion.

Amazon Interview Experience Set Off Campus for SDE-1, Banglore. Print all possible words from phone digits.

example of bitwise operators in c programming

Design Patterns Set 1 Introduction. Count all distinct pairs with difference equal to k. Top 10 Algorithms and Data Structures for Competitive Programming.

C Bitwise Operators: AND, OR, XOR, Complement and Shift Operations

Top 10 algorithms in Interview Questions. How to begin with Competitive Programming? Step by Step Guide for Placement Preparation. How to prepare for ACM-ICPC?

Rating 4,5 stars - 564 reviews
inserted by FC2 system