Click here to Skip to main content
15,844,602 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Now we will see the conversion from decimal to binary. Let us show the method with the help of an example. Suppose 95 needs to be converted to binary. Now we need to find the maximum value of n, where 2^n <= 95. The power of the two are 1,2,4,8,16,32,64,128. Here we see 64 <95 or 2^6 = 95. Then n is 6. And our binary number will be seven digits (0 to 6). Since 64 < 95, so this number can be taken. Then in place of sixty four (first from left to right from seventh) will be 1 (1xxxxxx). Now reduce the value of n 1. 64 + 2^5 = 64 + 32 = 96 which is greater than 95. So it cannot be taken. Therefore, I put 0 in the place of thirty-two (10xxxxx). This time reduce the value again, n = 4. 64 + 2^4= 64 + 16 = 80 < 95 .so 1 will sit in sixteen place(101xxxx)।. Now reduce the value of n ,n = 3. 80 + 2^3= 80 + 8 = 88 < 95 . Place of 8 will be 1 (1011xxx), Then n = 2 for 88 + 2^2 = 88 +4 = 92 < 95. 1 will also sit in place of four . Then n= 1. 92 + 2^1 = 92 + 2 = 94 < 95।. 1will add in the place of two(101111x). Now n = 0. 94 + 2^0 = 94 + 1 = 95. So I put 1 in the place of one's. Now the Binary digits will be : 1011111

How will I findout the value of n ? Can anyone tell me which method the author has used here?

What I have tried:

I cant understand how will I start?
Posted
Updated 11-Jul-22 21:29pm
Comments
jeron1 11-Jul-22 18:14pm    
Sounds like Method #2 in this link.

3 Ways to Convert from Decimal to Binary - wikiHow[^]
Gerry Schmitz 11-Jul-22 19:11pm    
He's converting base 10 to base 2. That's the "method".

https://www.thoughtco.com/changing-from-base-10-to-base-2-2312136
FatalError0x4c 11-Jul-22 22:29pm    
95|2
1|47 | 2
1 | 23 | 2
1 | 11 | 2
1 | 5
1 | 2
0 | 1 | 2
1 | 0 going up on the reminders 95 = 1011111
or in C++ https://pastebin.com/UJ8a5mN1

1 solution

Here, for instance, you may find a description (and an example) of such a method: Binary Calculator[^].
 
Share this answer
 
Comments
Patrice T 12-Jul-22 4:14am    
+5
CPallini 12-Jul-22 4:30am    
Thank you.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900