0
我很好奇什麼是在Ruby中將十六進制字符串轉換爲二進制字符串的最佳方法。Ruby:十六進制字符串到二進制字符串
I.e.
def get_binary_string(hex_string)
# what's the best way?
end
puts get_binary_string("2F")
output> "00101111"
任何幫助,將不勝感激。
我很好奇什麼是在Ruby中將十六進制字符串轉換爲二進制字符串的最佳方法。Ruby:十六進制字符串到二進制字符串
I.e.
def get_binary_string(hex_string)
# what's the best way?
end
puts get_binary_string("2F")
output> "00101111"
任何幫助,將不勝感激。
您可以在十六進制2F
轉換爲整數(47),然後將其轉換回二進制字符串(101111):
"2F".to_i(16).to_s(2)
# => "101111"