Beta
Convert integer to binary
Description:
Convert integer numbers to binary, without using the to_s(2)
method.
n_to_bits(0) # => 0
n_to_bits(1) # => 1
n_to_bits(2) # => 10
n_to_bits(5) # => 101
The second optional argument passes the minimum length. If your binary number is shorter than this length, then pad zeros on the left hand side to fulfill this minimum length like so:
n_to_bits(2, 4) # => 0010
n_to_bits(2, 8) # => 00000010
n_to_bits(5, 8) # => 00000101
Algorithms
Similar Kata:
Stats:
Created | May 15, 2017 |
Published | May 21, 2017 |
Warriors Trained | 232 |
Total Skips | 5 |
Total Code Submissions | 299 |
Total Times Completed | 63 |
Ruby Completions | 63 |
Total Stars | 3 |
% of votes with a positive feedback rating | 84% of 32 |
Total "Very Satisfied" Votes | 25 |
Total "Somewhat Satisfied" Votes | 4 |
Total "Not Satisfied" Votes | 3 |
Total Rank Assessments | 32 |
Average Assessed Rank | 7 kyu |
Highest Assessed Rank | 6 kyu |
Lowest Assessed Rank | 8 kyu |