How can I convert a bitstring to the binary form

I am using bitstring to perform an xor operation on the ith bit of a string:

string = bitstring(string ⊻ 1 <<i)

However the result will be a string, so I cannot continue with other i.

So I want to know how do I convert a bitstring (of the form “000000000000000000000001001”) to (0b1001)?

Thanks

You probably just shouldn’t call bitstring? But to answer your question:

julia> parse(UInt, "000000000000000000000001001", base = 2)
0x0000000000000009

I think your solution does work.
The reason I call bitstring is to perform the \xor operation. Otherwise it won’t work on ::String

But why do you need the string? Can’t you just work directly on the numbers? Converting to string and back to numbers is slow.

1 Like

There’s no method of xor which works with strings and you’re calling bitstring on the result of the xor anyway, so it’s hard to figure how bitstring helps you in any way here.

Oh I just realized that it also works for numbers. I initially thought if I write without bitstring then the result will be interpreted in base 10, which would not work sequentially as desired!

The docstring says “Bitwise exclusive or”, but the examples are all on Bools. Maybe there should be an update to the examples.