- Trending Categories
- Data Structure
- Operating System
- C Programming
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Before the introduction of Bitwise operators, a number is first converted into a string and later on, using string methods, some part of that number is sliced and the remaining part is executed. Here type-conversion i.e a number into a string is necessary. But the introduction of Bitwise or has made the task very easy. When Bitwise or is used there is no necessity of type-conversion and there is no need of using any kind of string methods, reducing the effort and length of the code.
In the following example, a string method called "string.substring()" is used to remove the last digit of a number.
<html> <body> <script> var str = '2345'; document.write((str.substring(0, str.length - 1))); </script> </body> </html>
But after the advent of Bitwise or, the type conversion and string methods are nowhere in the picture. Bitwise or has made the code very concise.
<html> <body> <script> document.write(2345 / 10 | 0) document.write("</br>"); document.write(2345 / 100 | 0) document.write("</br>"); document.write(2345 / 1000 | 0) </script> </body> </html>
234 23 2
- Sum of the first and last digit of a number in PL/SQL
- Find last five digits of a given five digit number raised to power five in C++
- Check if the first and last digit of the smallest number forms a prime in Python
- Find the sum of first and last digit for a number using C language
- Count of Numbers in Range where first digit is equal to last digit of the number in C++
- C program to find sum of digits of a five digit number