Convert binary to decimal in Julia

我怕爱的太早我们不能终老 提交于 2020-01-14 10:42:33

问题


I'd like to convert binary to decimal in Julia. It looks like parseint() became deprecated.

Is the below method the best way to do this?

julia> parse(Int,"111",2)
7

回答1:


Are you starting with a string? Then yes, that's the way. If you're just wanting to write a constant in binary, then it's much easier to just use the 0b111 syntax. By default, it constructs an unsigned integer (which is displayed in hexadecimal), but you can easily convert it to a signed integer with Int(0b111).

julia> 0b110111
0x37

julia> Int(0b110111)
55


来源:https://stackoverflow.com/questions/46451829/convert-binary-to-decimal-in-julia

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!