4 kyu
Float to Binary Conversion
257MRodalgaard
Description:
I need you to implement a function called float2bin
that converts a float number to the corresponding 32-bit binary value. This involves analysing each part of the input number and appointing each bit of the output accordingly. See visual explanation from wiki below:
Rules:
- The conversion should match the IEEE754 Single precision 32-bit technical standard.
- The implementation should be able to handle both Strings (
"123"
,"1.23"
) and Numbers (123
,1.23
) as input. - It should convert both positive and negative numbers.
- The output should always be a 32 characters long string, so padding of
0
's is necessary if input is not negative. - The point of this kata is to teach how floats are build on a binary level, so typed arrays are disabled.
Expectations and limitations:
- The input is valid numbers or strings of numbers.
- No weird edge cases are tested.
- Since there always is some rounding inaccuracy when working with floats, the last 5 characters in the output will not be checked. This is done using something similar to the
approx
function in the test fixture.
Here are some links to help you:
Bits
Algorithms
Similar Kata:
Stats:
Created | Sep 8, 2014 |
Published | Sep 8, 2014 |
Warriors Trained | 1490 |
Total Skips | 590 |
Total Code Submissions | 2304 |
Total Times Completed | 257 |
JavaScript Completions | 257 |
Total Stars | 110 |
% of votes with a positive feedback rating | 98% of 70 |
Total "Very Satisfied" Votes | 68 |
Total "Somewhat Satisfied" Votes | 1 |
Total "Not Satisfied" Votes | 1 |