How do you write a binary literal in ruby?

后端 未结 4 686
忘掉有多难
忘掉有多难 2021-02-18 13:33

Most languages (Ruby included) allow number literals to be written in at least three bases: decimal, octal and hexadecimal. Numbers in decimal base is the usual thing and are wr

4条回答
  •  攒了一身酷
    2021-02-18 14:07

    For literals, the prefix is 0b. So

    0b100 #=> 4
    

    Be aware that the same exists to format strings:

    "%b" % 4 #=> "100"
    

提交回复
热议问题