DEV Community

Cover image for How to Convert Between Decimal and Binary Numbers – Beginner’s Guide
s mathavi
s mathavi

Posted on

How to Convert Between Decimal and Binary Numbers – Beginner’s Guide

Introduction:
Computers only understand 0s and 1s (binary). We humans use decimal numbers (0–9). So, converting between decimal and binary is important in computer science.

Decimal → Binary (Division by 2 Method)

Steps:

  • Take the decimal number.
  • Divide it by 2.
  • Write down the remainder (0 or 1).
  • Divide the quotient again by 2.
  • Repeat until quotient = 0.
  • Read the remainders from bottom to top → Binary number

Example:

Convert 24 → Binary
24 ÷ 2 = 12 remainder 0
12 ÷ 2 = 6 remainder 0
6 ÷ 2 = 3 remainder 0
3 ÷ 2 = 1 remainder 1
1 ÷ 2 = 0 remainder 1
Binary = 11000
Enter fullscreen mode Exit fullscreen mode

So, 24 (decimal) = 11000 (binary)

Binary → Decimal (Powers of 2 Method)

Steps:

  • Take the binary number.
  • Write powers of 2 under each digit (starting from right, 2⁰).
  • Multiply digit × power of 2.
  • Add all results.
  • That’s the decimal number.

Example:

Convert 11000 → Decimal
1 × 2^4 = 16
1 × 2^3 = 8
0 × 2^2 = 0
0 × 2^1 = 0
0 × 2^0 = 0
Total = 24
Enter fullscreen mode Exit fullscreen mode

So, 11000 (binary) = 24 (decimal)

Binary conversion is the foundation of computer science. Once we practice a few examples, it becomes very easy.

”Thanks for reading! See you soon in a different style with more coding insights.”

Top comments (4)

Collapse
 
sathish_226_ profile image
Sathish A

Excellent madhavi mam, it's easy to understand how to decimal to binary.

Collapse
 
s_mathavi_2fa1e3ea8514f34 profile image
s mathavi

Thank You sir

Collapse
 
parag_nandy_roy profile image
Parag Nandy Roy

Super clear explanation..

Collapse
 
s_mathavi_2fa1e3ea8514f34 profile image
s mathavi

Thank you