BigInt and xor
Rene Zwanenburg via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Tue Mar 24 09:29:02 PDT 2015
On Tuesday, 24 March 2015 at 15:45:36 UTC, Dennis Ritchie wrote:
> Tell me, please, how can I replace this code?
>
> import std.conv : to;
> import std.bigint : BigInt;
> import std.string : format;
> import std.stdio : writeln;
>
> void main() {
>
> BigInt[10] bitArr;
>
> ulong n = 18_446_724_073_709_551_614U;
>
> bitArr[0] = format("%b", n).to!BigInt;
>
> writeln(bitArr[0]);
> writeln(bitArr[0] ^ 1); // not work
>
> }
>
> Output:
> 1111111111111111111011011100111101100011000110101011111111111110
> 1111111111111111111011011100111101100011000110101011111111111111
Looks right to me. What output would you expect?
Also, if you need a bit array you can simply use std.container's
Array!bool. It's specialized for bool and uses only one bit per
element.
More information about the Digitalmars-d-learn
mailing list