Example 96: Print Binary Value

Learn how to print the binary value of a number using bitwise operators.

Problem

Define a showBits() function that would print the binary value stored in a one-byte entity.

Remember that you can only use bitwise operators to solve this challenge.

Example

Input Output
10 00001010
15 00001111
23 00010111
32 00100000

Try it yourself

Try to solve this question on your own in the code widget below. If you get stuck, you can always refer to the solution provided.

Level up your interview prep. Join Educative to access 80+ hands-on prep courses.