-
Notifications
You must be signed in to change notification settings - Fork 5.4k
Description
Description
Biginteger loses precision when working with byte arrays.
([bigint](([System.Net.IPAddress]"::ffff:169.254.1.1").GetAddressBytes()) -band [bigint](([System.Net.IPAddress]"::ffff:169.254.0.0").GetAddressBytes())).ToByteArray() -join " "
Results in:
0 0 0 0 0 0 0 0 0 0 255 255 169 254 0
instead of
0 0 0 0 0 0 0 0 0 0 255 255 169 254 0 0
because of:
([IPAddress]'::ffff:169.254.0.0').GetAddressBytes() -join " " returns 0 0 0 0 0 0 0 0 0 0 255 255 169 254 0 0
and ([BigInt]([IPAddress]'::ffff:169.254.0.0').GetAddressBytes()).ToByteArray() -join " " loses that precision and only returns 0 0 0 0 0 0 0 0 0 0 255 255 169 254 0 instead.
alternatively to "fixing" this precision issue in biginteger, also implementing the binary operators for [System.Byte[]] would work, so that a byte array doesn't need to be converted to a biginteger at all.
Configuration
dotnet --list-runtimes
Microsoft.NETCore.App 3.1.8 [/usr/share/dotnet/shared/Microsoft.NETCore.App]
On x64 ArchLinux