+ 1

[CHALLENGE] write a code to convert numbers from decimal to binary . The input being a non-negative INTEGER OR FRACTION DECIMAL.

I MEAN THE INPUT WOULD BE 100.625 in decimal and output will be 1100100.101. ☆☆☆☆☆CAN YOU DO THAT IT'S A CHALLENGE. https://code.sololearn.com/cULmik5uhuDz/?ref=app

4th Mar 2018, 8:21 AM
Someone
Someone - avatar
15 odpowiedzi
+ 14
might it comes in already existing challenge https://www.sololearn.com/learn/4943/?ref=app
4th Mar 2018, 8:43 AM
Gaurav Agrawal
Gaurav Agrawal - avatar
+ 3
https://code.sololearn.com/coLY4m0wPfvW/?ref=app
8th Mar 2018, 6:10 PM
Solo Wanderer 4315
Solo Wanderer 4315 - avatar
+ 2
really good kinshuk appreciable code you got the challenge right
12th Mar 2018, 8:43 AM
Someone
Someone - avatar
+ 1
@ Tulsi.. heres your wanted output... https://code.sololearn.com/c3p1vQa6DNqi/?ref=app
4th Mar 2018, 9:57 AM
sayan chandra
sayan chandra - avatar
+ 1
So Is my code wrong?
4th Mar 2018, 10:15 AM
Someone
Someone - avatar
+ 1
Mr Ben Davis, I thank you most heartily for your advice and also for congrating me
12th Mar 2018, 8:44 AM
Someone
Someone - avatar
0
I MEANT THAT if I enter a fraction decimal like 36.5 the output will be 100100.1 BUT THE CHALLENGE IN BASE CONVERTOR IS OF ONLY NON-NEGATIVE INTEGER NOT FRACTIONS LIKE 55.5 DO YOU UNDERSTAND WHAT I MEAN OK TRY TO ENTER 100.625 IN YOUR CODE AND SEE THE OUTPUT.
4th Mar 2018, 9:06 AM
Someone
Someone - avatar
0
how would you encode the position of the decimal point in your output number? 1010100.001 is useless as binary does not include a decimal point. this is one of the reasons that integer and float are different data types which need declaring... they must be treated totally differently. floats work using exponent and mantissa. 5he mantissa part is like a simple integer, which is modified by the exponent to increase the number's size OR precision by shifting the mantissa left OR right. Wikipedia explains it better: https://en.m.wikipedia.org/wiki/Significand
4th Mar 2018, 9:21 AM
Ben-Davis
Ben-Davis - avatar
0
@ Tulsi... i see no pblm in ur code😀😀😀
4th Mar 2018, 10:19 AM
sayan chandra
sayan chandra - avatar
0
so your example of 36.5 would be 1001001 mantissa and an exponent of -1 (eg 11111110 I think)
4th Mar 2018, 10:22 AM
Ben-Davis
Ben-Davis - avatar
0
I think you need to have a discussion with one of your most trusted professors and ask him why philosophical truths are not so useful when discussing engineering. Alternatively just spend a little more time to understand the basis of my comment and less time telling me what you think I don't understand in order to defend your own ego. Forgive me if I expressed my opinion too strongly, but don't allow that to fog the discussion. I was very clear why conflating an exponent with a floating decimal is wrong (suboptimal to be more polite). It obfuscates the true nature of the data-type which can cause so much confusion for learners with a weaker grasp of the subject than yourself. Telling me that I don't understand floating point numbers is just stupid, lazy (because you should maybe reread and ponder my argument longer before responding), and rude.
7th Mar 2018, 4:38 PM
Ben-Davis
Ben-Davis - avatar
0
@Sayan Chandra: It just occurred to me that maybe your strong reaction to my comment was not because of an insufferable ego, but possibly to defend Tulsi Dey. Do you consider yourself a mentor or a guide? If so, I congratulate you for your noble intention and intense loyalty. I didn't intend to disparage Tulsi for his efforts.... the code he produced was well written and within the specification set by the challenge. This makes it good code within that specific context. (Congrats Tulsi Dey). The challenge set, also wasn't a bad challenge, I acknowledged in my previous comment that there was merit in the exercise, although the concept was flawed (I admit I sounded harsher than that, sorry). I hope you can consider the possibility that I share your aspiration to educate and enrich other younger or less experienced developers. (I am now 45 years old, and have been an IT professional since around 1993, {possibly before you were born} and am also a passionate educator ).
7th Mar 2018, 5:52 PM
Ben-Davis
Ben-Davis - avatar
0
(my comment was too long, so I had to split in to 2 comments . It continues...): My final point is that you may not be serving Tulsi (or other newer programmers in this community) in the best way by belittling my criticism. The point I wanted to make may have been overshadowed by bold judgemental language, but I am sure Tulsi's skin is thicker than you think. When there is a lesson to be learned and an eager learner, harsh words are quickly put aside in favour of examining the concepts and knowledge being offered. You assume that because you understand how a floating point serves the same function as an exponent, that Tulsi, and anyone else who reads this thread will understand it as well as you do. It really pays to cover the basics with zero assumptions. It is often the things we think we understand that cause the most confusion and frustration later on. we have heard (read) you say the floating point is exactly the same as the exponent. Why not take the time to enrich Tulsi's understanding by explaining exactly how exponents work and how they are both similar and different from the floating point, and how floating point numbers are encoded? Maybe that would be a good discussion for a new thread?
7th Mar 2018, 5:54 PM
Ben-Davis
Ben-Davis - avatar
- 1
It may be harmless but it is also useless and meaningless. It is better to learn how a computer reads a floating point number rather than create a hybrid numbering system that is both hard for humans to read(because it is binary) and meaningless for a computer (because it diverges from standard methodology). This challenge may be good as an exercise to stretch your brain and increase confidence with manipulating numbers and getting used to concepts around binary... so please don't let me disturb your enjoyment ... but it is based on a false notion regarding how computers work, so I thought it would be most beneficial to point that out for anyone who could be confused by this challenge.
4th Mar 2018, 2:55 PM
Ben-Davis
Ben-Davis - avatar
- 2
sorry Mr Chandra, I thought you were an engineer and would appreciate the subtleties and nuances of this subject. Please forgive me for not recognising that you are a math ideologue who cannot bear to be contradicted. I was just trying to help and to contribute to other people's useful and meaningful understanding of the subject. please continue in your own little bubble of self congratulation and upvoting all your own comments. You are A BIG MAN!!!
5th Mar 2018, 6:38 AM
Ben-Davis
Ben-Davis - avatar