- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Rishikesh Kumar Rishi has Published 1162 Articles
![Rishikesh Kumar Rishi](https://www.tutorialspoint.com/assets/profiles/318007/profile/60_254496-1615815423.jpg)
Rishikesh Kumar Rishi
1K+ Views
ExamplesFor example, 101, 11, 11011 and 1001001 set bits count 2, 2, 4 and 3 respectively.Approach to solve this problemStep 1 − Convert number into binary representation.Step 2 − Count the number of 1s; return count.Example Live Demopackage main import ( "fmt" "strconv" ) func NumOfSetBits(n int) int{ ... Read More
![Rishikesh Kumar Rishi](https://www.tutorialspoint.com/assets/profiles/318007/profile/60_254496-1615815423.jpg)
Rishikesh Kumar Rishi
178 Views
ExamplesFor example, 101, 11, 11011, 1001001 are Palindrome. 100, 10010 are not Palindrome.Approach to solve this problemStep 1 − Convert number into binary representation.Step 2 − Traverse the converted binary representation from both side and check whether representation is palindrome or not.Example Live Demopackage main import ( "fmt" "strconv" ... Read More
![Rishikesh Kumar Rishi](https://www.tutorialspoint.com/assets/profiles/318007/profile/60_254496-1615815423.jpg)
Rishikesh Kumar Rishi
90 Views
ExamplesConsider two numbers m = 65 => 01000001 and n = 80 => 01010000Number of bits flipped is 2.Approach to solve this problemStep 1 − Convert both numbers into bits.Step 2 − Count number of bits are flipped.Example Live Demopackage main import ( "fmt" "strconv" ) func FindBits(x, y ... Read More
![Rishikesh Kumar Rishi](https://www.tutorialspoint.com/assets/profiles/318007/profile/60_254496-1615815423.jpg)
Rishikesh Kumar Rishi
678 Views
Definition − Parity refers to the count of 1s. If count of 1s is even, then it’s even parity; and if the count of 1s is odd, then the parity is Odd.ExamplesConsider n = 20(00010100)Parity of the given number 20 is even.Approach to solve this problemStep 1 − Define a ... Read More
![Rishikesh Kumar Rishi](https://www.tutorialspoint.com/assets/profiles/318007/profile/60_254496-1615815423.jpg)
Rishikesh Kumar Rishi
241 Views
ExamplesConsider n = 20(00010100)Now return log2(20 & -20) => 2+1 => 3Approach to solve this problemStep 1 − Define a method, where n and is an argument, return type is int.Step 2 − Return log2(n & -n)+1.Examplepackage main import ( "fmt" "math" "strconv" ) func FindRightMostSetBit(n int) ... Read More
![Rishikesh Kumar Rishi](https://www.tutorialspoint.com/assets/profiles/318007/profile/60_254496-1615815423.jpg)
Rishikesh Kumar Rishi
501 Views
ExamplesConsider n = 16(00010000)Now find x = n-1 => 15(00001111) => x & n => 0Approach to solve this problemStep 1 − Define a method, where n and is an argument, returns type is int.Step 2 − Perform x = n & n-1.Step 3 − If x is 0, then ... Read More
![Rishikesh Kumar Rishi](https://www.tutorialspoint.com/assets/profiles/318007/profile/60_254496-1615815423.jpg)
Rishikesh Kumar Rishi
114 Views
ExamplesConsider n = 20(00010100), k = 3.After toggling the kth bit of the given number: 00010000 => 16.Approach to solve this problemStep 1 − Define a method, where n and k would be the arguments, returns type is int.Step 2 − Perform AND operation with n ^ (1
![Rishikesh Kumar Rishi](https://www.tutorialspoint.com/assets/profiles/318007/profile/60_254496-1615815423.jpg)
Rishikesh Kumar Rishi
119 Views
ExampleConsider n = 20(00010100), k = 3 The result after turning off the 3rd bit => 00010000 & ^(1 16sApproach to solve this problemStep 1 − Define a method, where n and k would be the arguments, return type is int.Step 2 − Perform AND operation with n & ^(1