Mastering Metasploit
上QQ阅读APP看书,第一时间看更新

Conversions in Ruby

While working with exploits and modules, we will require tons of conversion operations. Let's see some of the conversions we will use in the upcoming sections:

  • Hexadecimal to decimal conversion:
    • It's quite easy to convert a value to a decimal from a hexadecimal in Ruby using the inbuilt hex function. Let's look at an example:
irb(main):021:0> a= "10"
=> "10"
irb(main):022:0> a.hex
=> 16
    • We can see we got the value 16 for a hexadecimal value of 10.
  • Decimal to hexadecimal conversion:
    • The opposite of the preceding function can be performed with the to_s function, as follows:
irb(main):028:0> 16.to_s(16)
=> "10"