How do I convert a binary string to a number in Perl?

后端 未结 5 1635
别跟我提以往
别跟我提以往 2020-12-13 00:44

How can I convert the binary string $x_bin=\"0001001100101\" to its numeric value $x_num=613 in Perl?

5条回答
  •  伪装坚强ぢ
    2020-12-13 00:51

    Actually you can just stick '0b' on the front and it's treated as a binary number.

    perl -le 'print 0b101'
    5
    

    But this only works for a bareword.

提交回复
热议问题