In many languages there's a pair of functions, chr()
and ord()
, which convert between numbers and character values. In some languages, ord()
is called asc()
.
Ruby has String#chr
, which works great:
>> 65.chr
A
Fair enough. But how do you go the other way?
"A".each_byte do |byte|
puts byte
end
prints:
65
and that's pretty close to what I want. But I'd really rather avoid a loop -- I'm looking for something short enough to be readable when declaring a const
.