How to I display the binary equivalent of a number? I tried this:
b = 0b1101
puts b # returns decimal value ( 13 )
b.to_bn # generates “unable to convert FIXNUM to STRING…” error.
How to I display the binary equivalent of a number? I tried this:
b = 0b1101
puts b # returns decimal value ( 13 )
b.to_bn # generates “unable to convert FIXNUM to STRING…” error.
Larry K. wrote:
How to I display the binary equivalent of a number? I tried this:
b = 0b1101
puts b # returns decimal value ( 13 )b.to_bn # generates “unable to convert FIXNUM to STRING…” error.
.to_s(base)
So, in this case
13.to_s(2)
=> “1101”
How to I display the binary equivalent of a number? I tried this:
b = 0b1101
puts b # returns decimal value ( 13 )b.to_bn # generates “unable to convert FIXNUM to STRING…” error.
b.to_s(2)
How elegant!, Wonderful!
Thanks,
-Larry
This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.
Sponsor our Newsletter | Privacy Policy | Terms of Service | Remote Ruby Jobs