Hi, i am asking the player to put a number, for example 14.125 and i need to convert it without using arrays. 14.125 should be 1110.001 Any ideas?
Quick serach gives results for ints to binary conversion. https://www.sanfoundry.com/csharp-program-convert-decimal-binary/ You can adapt it to deal with reminder.
Just ask your self question, how you going represent binary number as single char? (if even think of using it) string is an array of chars.
Just do the math directly. Hints for a trivial approach: - optionally, you can break the problem into two parts: integer part, decimal places. If you want to break them up: one cast to int, then substract the integer from the floating point value in order to get the decimal parts. - binary is just some math with 2^n where n is an integer. Though, don't start using Math.Pow, instead use shift operators - extracting the bits can either be done with bit wise operations or simple math operations like division (for the latter you will need the remainder once at the end) - both can be done in a loop while you keep changing the n in 2^n and do the operations. The decimal places can be done in a similar fashion. Those are just two of many available approaches. Depending on the language you could also work on the memory level directly. Not sure though why you ask this in a game dev forum.
Thanks for your response, i found a solution. I ask it here because it is about scripting and this is the forum i am use to.