What is the most efficient binary representation of unsigned integers in Julia?

Here is a simple example how to encode a standard cross-over (I am writing it out of my head so there might be bugs or corner cases would have to be handled in some special way).

function crossover(a::UInt32, b::UInt32, n)
    low = UInt32(1<<n - 1)
    high = ~low
    return (a & low) | (b & high), (b & low) | (a & high)
end

and here is a single point cross-over:

function crossover(a::UInt32, b::UInt32, n)
    mask = UInt32(1<<(n - 1))
    notmask = ~mask
    return (a & mask) | (b & notmask), (b & mask) | (a & notmask)
end

7 Likes