Bit Strings
MimiqCircuitsBase.BitString
— TypeBitString(numbits)
Representation of the state of a register of bits. Can also represent the state of a register of qubits with defined values for each qubit (0 or 1).
Examples
julia> BitString(16)
16-bits BitString with integer value 0:
00000000 00000000
julia> bs = BitString(16, [1,2,3,4])
16-bits BitString with integer value 15:
11110000 00000000
julia> bs[10] = 1
1
julia> bs
16-bits BitString with integer value 527:
11110000 01000000
julia> bitstring_to_integer(bs)
527
julia> typeof(ans)
BigInt
julia> bitstring_to_integer(bs, Int)
527
julia> typeof(ans)
Int64
There are many different ways to get bit states:
julia> bs = BitString(30, 2344574)
30-bits BitString with integer value 2344574:
01111110 01100011 11000100 000000
julia> ones(BitString, 10) # or also trues(BitString, 10)
10-bits BitString with integer value 1023:
11111111 11
julia> zeros(BitString, 10) # or also falses(BitString, 10)
10-bits BitString with integer value 0:
00000000 00
julia> BitString(16) do i
iseven(i)
end
16-bits BitString with integer value 43690:
01010101 01010101
MimiqCircuitsBase.bitstring_to_index
— Methodbitstring_to_index(bitstring)
Convert a bitstring into the corresponding index.
This is useful for indexing, for example, a vector of states.
MimiqCircuitsBase.bitstring_to_integer
— Functionbitstring_to_integer(bitstring[, T])
Convert a bitstring into its corresponding integer.
MimiqCircuitsBase.nonzeros
— Methodnonzeros(bitstring)
Return the indices of the non-zero qubits in a bit state.
MimiqCircuitsBase.to01
— Methodto01(bitstring[, endianess=:big])
Converts a BitString into a string of 0 and 1 characters. Optionally endianess can be specified, which can be either :big
or :little
.
Examples
julia> to01(bs"10011")
"10011"
julia> to01(bs"10011"; endianess=:big)
"10011"
julia> to01(bs"10011"; endianess=:little)
"11001"
MimiqCircuitsBase.tobits
— Methodtobits(bitstring)
Get the underlying BitVector of a bit state.
MimiqCircuitsBase.@bs_str
— Macromacro bs_str(s)
Convert a string into a bit state.
Examples
julia> bs"101011"
6-bits BitString with integer value 53:
101011