to_hex
is the exact inverse of to_base64
:
to_base64
- put string in an array:
[self]
- call pack with
H*
:[self].pack("H*")
- put string in an array:
[[self].pack("H*")]
- call pack with
m0
:[[self].pack("H*")].pack("m0")
to_hex
- call unpack with
m0
:self.unpack("m0")
- extract string from array:
self.unpack("m0").first
- call unpack with
H*
:self.unpack("m0").first.unpack("H*")
- extract string from array:
self.unpack("m0").first.unpack("H*").first
That's how you undo operations, by applying the inverse operations:
a = 5
(a + 4) * 3
#=> 27
And the other way around:
a = 27
(a / 3) - 4
#=> 5
a.pack
is the inverse of a.unpack
and a.first
is the inverse of [a]