Convert Base64 string to Integer in Ruby

I would like to convert Base64 values ​​such as "AAAAAAAAABI =" to the corresponding integer. I was bustling with Base64.decode64, but it was not obvious how this would be part of the solution.

irb > require 'base64' => true irb > Base64.decode64('AAAAAAAAABI=') => "\x00\x00\x00\x00\x00\x00\x00\x12" 
+4
source share
1 answer

This should be what you need. If not, see String#unpack for more information on what it can do.

 require 'base64' i = Base64.decode64('AAAAAAAAABI=') i.unpack('q*').first # => 1297036692682702848 
+3
source

Source: https://habr.com/ru/post/1347148/


All Articles