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

Stats:

CreatedMay 15, 2017
PublishedMay 21, 2017
Warriors Trained232
Total Skips5
Total Code Submissions299
Total Times Completed63
Ruby Completions63
Total Stars3
% of votes with a positive feedback rating84% of 32
Total "Very Satisfied" Votes25
Total "Somewhat Satisfied" Votes4
Total "Not Satisfied" Votes3
Total Rank Assessments32
Average Assessed Rank
7 kyu
Highest Assessed Rank
6 kyu
Lowest Assessed Rank
8 kyu
Ad
Contributors
  • BurntCaramel Avatar
Ad