Skip to content

Instantly share code, notes, and snippets.

@sebyx07
Created May 27, 2014 18:41
Show Gist options
  • Save sebyx07/909ef1f2aa6676191691 to your computer and use it in GitHub Desktop.
Save sebyx07/909ef1f2aa6676191691 to your computer and use it in GitHub Desktop.
class Fixnum
def convert_base(to)
self.to_s(to).to_i
end
end
i=1
puts ("Enter input:")
input = gets.chomp
input=input.to_i(10).convert_base(2)
puts ("Output:"), input
bit=Array.new(8)
#8 BIT REPRESENTATION
if input.convert_base(10)>0
bit[0]=0
else
bit[0]=1
end
while(i<8)
bit.push input[i]
i += 1
end
bit.each { |a| print a, "" }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment