Re: OT (sorry) base64 conversion in ruby

Gavin Kistner
Thu, 05 May 2005 12:40:34 -0000

On May 4, 2005, at 11:59 PM, Rob Park wrote:
> Hi everybody. I''m trying to convert a hex value into base64, but
I''m
> having some problems. The problem is that Base64.encode64 is doing a
> conversion based on the string representation of the hex value
[snip]
> Anybody have any ideas? The obvious:
>
> Base64.encode64("60d06a02dc53d67b123647f12a0d896d5d839294")

Is this really a single base-16 number?
"60d06a02dc53d67b123647f12a0d896d5d839294".to_i( 16 )
#=> 552710903876121934266138116081162544013019157140

Or is it really a series of 40 bytes represented as hex pairs?

"60d06a02dc53d67b123647f12a0d896d5d839294".scan( /../ ).each do |byte|
   puts byte.to_i( 16 )
end