Livt packages
Eccelerators.BitTwiddling
Version 0.1.1
Readable 32-bit bit manipulation, counting, scanning, permutation, and arithmetic utilities for Livt.
Published files (26)
tests/permutation/BitPermutationTest.lvt
namespace Eccelerators.BitTwiddling.Tests.Permutation
using Eccelerators.BitTwiddling.Permutation
@Test
component BitPermutationTest
{
@Test
fn TestReverse32()
{
assert BitPermutation.Reverse32(0) == (0 as uint)
assert BitPermutation.Reverse32(1) == (0x80000000 as uint)
assert BitPermutation.Reverse32(0xAAAAAAAA) == (0x55555555 as uint)
assert BitPermutation.Reverse32(0x01234567) == (0xE6A2C480 as uint)
var reversed: uint = BitPermutation.Reverse32(0x12345678)
assert BitPermutation.Reverse32(reversed) == (0x12345678 as uint)
}
@Test
fn TestReverseByteAndByteSwap()
{
assert BitPermutation.ReverseByte(0x00) == 0x00
assert BitPermutation.ReverseByte(0x01) == 0x80
assert BitPermutation.ReverseByte(0x96) == 0x69
assert BitPermutation.ByteSwap32(0x12345678) == (0x78563412 as uint)
assert BitPermutation.ByteSwap32(0xAABBCCDD) == (0xDDCCBBAA as uint)
}
@Test
fn TestRotations()
{
assert BitPermutation.RotateLeft32(0x80000001, 1) == (0x00000003 as uint)
assert BitPermutation.RotateRight32(0x80000001, 1) == (0xC0000000 as uint)
assert BitPermutation.RotateLeft32(0x12345678, 0) == (0x12345678 as uint)
assert BitPermutation.RotateRight32(0x12345678, 32) == (0x12345678 as uint)
assert BitPermutation.RotateLeft32(0x12345678, -1) == (0x12345678 as uint)
}
}