Practice
Resources
Contests
Online IDE
New
Free Mock
Scaler
Practice
Improve your coding skills with our resources
Contests
Compete in popular contests with top coders
Scaler
Explore Offerings by SCALER

Welcome to Interviewbit, help us create the best experience for you!

Currently, You are a:

Few details about your education

College/University *
Enter the name of your college
Branch *
Year of completion *

Few details about your education

College/University *
Enter the name of your college
Branch *
Year of completion *

Few details about your career...

Current Company *
Enter company name
Experience *

You're all set!

Begin your success journey!

Sign Up using
Full name *
Email *
Password *

By creating an account, I acknowledge that I have read and agree to InterviewBit’s Terms and Privacy Policy .

Welcome back!

Log In using
Email *
Password *

Math

Go to Problems

Level 1

Jump to Level 2

Level 2

Jump to Level 3

Level 3

Jump to Level 4

Level 4

Jump to Level 5

Level 5

Jump to Level 6

Level 6

Jump to Level 7

Level 7

Jump to Level 8

Level 8

Be a Code Ninja!

Binary number system

Unary, where we just write 1, 11, 111… just goes on forever. Binary, with two options (1 and 0) looks like this:

    1: 1
    2: 10 (we’re full – tick over)
    3: 11
    4: 100 (we’re full again – tick over)
    5: 101
    6: 110
    7: 111
    8: 1000 (tick over again)

and so on …

Now, how do we convert an arbitrary binary number to its decimal equivalent? Obviously counting and matching is not an option.

Let us first look at the value of 10000...n times ( 1 followed by n 0s ):

This number will only come after we have tried all possible n digit numbers in the binary system which has:

      2 * 2 * 2 * .. n times possibilities  ( every position can either have 0 or 1 ) 
   =  2^n possibility which covers numbers from 0 to 2^n - 1.

So, the value of 1000..n times = 2n.

Now any number like 1010110 can be expressed as 1000000 + 10000 + 100 + 10 = 2^6 + 2^4 + 2^2 + 2^1.

Hence, if the binary representation is An An-1 An-2 ... A1 A0, then the corresponding value is

A0 * 2^0 + A1 * 2^1 + A2 * 2^2 + .... + An * 2^n

Now look at the reverse process. Which is given a decimal number N, how do we convert it to binary.
To do this conversion, we need to divide repeatedly by 2, keeping track of the remainders as we go. Watch below:
Let us say our number is 357.

Number conversion to binary

Thus the number converts to 101100101

Walkthrough Example :
DECBIN

Serious about Learning Programming ?

Learn this and a lot more with Scaler Academy's industry vetted curriculum which covers Data Structures & Algorithms in depth.

Math Problems

Base conversion
Problem Score Companies Time Status
Excel Column Number 175 23:19
Excel Column Title 175 41:11
Digit op
Problem Score Companies Time Status
Palindrome Integer 200
HCL
17:28
Reverse integer 200 28:36
Next Smallest Palindrome! 400 58:55
Number encoding
Problem Score Companies Time Status
Next Similar Number 200 54:52
Rearrange Array 250
49:03
Array dp
Problem Score Companies Time Status
Numbers of length N and value less than K 200
89:58
Combinatorics
Problem Score Companies Time Status
City Tour 300
61:23
Grid Unique Paths 375 32:35
Free Mock Assessment
Help us know you better for the best experience
Current Employer *
Enter company name
College you graduated from *
Enter university name
Phone Number *
OTP will be sent to this number for verification
+1
+1
Change Number
Edit
Resend OTP
By Continuing I agree to be contacted by Scaler in the future.
Already have an account? Log in