Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Convert binary to decimal in Julia

Tags:

julia

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
like image 712
spacetyper Avatar asked Sep 27 '17 15:09

spacetyper


1 Answers

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
like image 98
mbauman Avatar answered Nov 16 '22 07:11

mbauman