Apply for Zend Framework Certification Training

c

< Passing pointers to functions and returning pointers from functions Pointer Arithmetic in C >




How to convert dec to binary
To convert a decimal number to binary, repeatedly divide the number 
by 2 and record the remainder.
Example: Convert 25 to Binary
Division Quotient Remainder
25 ÷ 2 12 1
12 ÷ 2 6 0
6 ÷ 2 3 0
3 ÷ 2 1 1
1 ÷ 2 0 1
Now read the remainders from bottom to top:
11001
Therefore:
25?? = 11001?
Another Example: 10
10 ÷ 2 = 5   remainder 0
 5 ÷ 2 = 2   remainder 1
 2 ÷ 2 = 1   remainder 0
 1 ÷ 2 = 0   remainder 1
Read from bottom to top:
1010
So:
10?? = 1010?
Quick Rule
Decimal → Binary:
Divide by 2
     ↓
Write remainder (0 or 1)
     ↓
Divide quotient by 2
     ↓
Repeat until quotient = 0
     ↓
Read remainders from bottom to top
Common Examples
Decimal Binary
2 10
3 11
4 100
5 101
8 1000
10 1010
15 1111
16 10000
20 10100
25 11001
50 110010
100 1100100
Important for C programming: Binary numbers are commonly represented using bits, where each position represents a power of 2:
1  1  0  0  1
↑  ↑  ↑  ↑  ↑
16 8  4  2  1
16 + 8 + 0 + 0 + 1 = 25
If you want, I can also explain how to convert binary → decimal and give 10 practice questions with answers.
Try one of these next
Binary to decimal
Convert a specific number
Binary to Decimal Conversion
To convert a binary number to decimal, multiply each binary digit by its corresponding power of 2, starting from the rightmost digit with \(2^0\).
Example: Convert 11001? to Decimal
Write the powers of 2 from right to left:
Binary digit 1 1 0 0 1
Power of 2 2? 2³ 2² 2¹ 2?
Value 16 8 4 2 1
Now multiply each digit:
(1 × 16) + (1 × 8) + (0 × 4) + (0 × 2) + (1 × 1)
= 16 + 8 + 0 + 0 + 1
= 25
Therefore:
11001? = 25??
Easy Method to Remember
Starting from the right:
1 → 2? → 1
2 → 2¹ → 2
3 → 2² → 4
4 → 2³ → 8
5 → 2? → 16
6 → 2? → 32
For example:
10110?
= 1×16 + 0×8 + 1×4 + 1×2 + 0×1
= 16 + 0 + 4 + 2 + 0
= 22
So, 10110? = 22??.
why we convert dec to binary
We convert decimal to binary because computers and digital electronic systems work internally using two states: 0 and 1.
Why Binary?
Humans normally use the decimal system (base 10):
0 1 2 3 4 5 6 7 8 9
Computers use the binary system (base 2):
0 1
These two values can represent electronic states such as:
0 → OFF / LOW
1 → ON / HIGH
Example
Suppose we have the decimal number:
10
Its binary representation is:
10?? = 1010?
The computer can represent 1010 using four bits:
1   0   1   0
↑   ↑   ↑   ↑
ON OFF  ON OFF

< Passing pointers to functions and returning pointers from functions Pointer Arithmetic in C >



Ask a question



  • Question:
    {{questionlistdata.blog_question_description}}
    • Answer:
      {{answer.blog_answer_description  }}
    Replay to Question


Back to Top