Data update
This commit is contained in:
parent
8e4e15fa56
commit
72eb4943cb
1853 changed files with 35514 additions and 9441 deletions
|
|
@ -1,9 +1,10 @@
|
|||
# numbers are doubles, bit operations use 32 bits and are unsigned
|
||||
x = 11
|
||||
y = 2
|
||||
print bitnot x
|
||||
print bitand x y
|
||||
print bitor x y
|
||||
print bitxor x y
|
||||
print bitshift x y
|
||||
print bitshift x -y
|
||||
# numbers are doubles, bit operations are unsigned, truncate
|
||||
# the fractional part and use 53 integer bits
|
||||
a = 14
|
||||
b = 3
|
||||
print bitand a b
|
||||
print bitor a b
|
||||
print bitxor a b
|
||||
print bitshift a b
|
||||
print bitshift a -b
|
||||
print bitand a bitnot b
|
||||
|
|
|
|||
|
|
@ -0,0 +1,43 @@
|
|||
module binary_ops{
|
||||
select case random(1, 6)
|
||||
case 1
|
||||
Double x=10, y=2
|
||||
case 2
|
||||
Decimal x=10, y=2
|
||||
case 3
|
||||
Integer x=10, y=2
|
||||
case 4
|
||||
Long x=10, y=2
|
||||
case 5 ' byte from 0 to 255 (unsigned)
|
||||
Byte x=10, y=2
|
||||
case else
|
||||
Long Long x=10, y=2
|
||||
end select
|
||||
print type$(x)
|
||||
//x & y values from 0 to 4294967295
|
||||
print binary.not(x)=4294967285, sint(binary.not(x))=-11
|
||||
print binary.and(x, y)=2
|
||||
print binary.or(x, y)=10
|
||||
// y values -31 to 31
|
||||
print binary.xor(x, y)=8
|
||||
print binary.shift(x, y)=40
|
||||
print binary.shift(x, -y)=2
|
||||
print binary.rotate(x, y)=40
|
||||
print binary.rotate(x, -y)=2147483650, sint(binary.rotate(x, -y))=-2147483646
|
||||
// Binary.Neg return Unsigned from signed values: -2147483648 (0x8000_0000&) to 2147483647 (0x7FFF_FFFF&)
|
||||
// values>2147483647 return 2147483648
|
||||
// values <-2147483648 return 2147483647
|
||||
// 0xFFFF_ABCD& (signed value), 0xFFFF_ABCD unsinged value same bits
|
||||
print 0xFFFF_ABCD&=-21555, 0xFFFF_ABCD=4294945741, sint(0xFFFF_ABCD)=-21555
|
||||
print Binary.Neg(0xFFFF_ABCD&)=21554, Binary.Not(0xFFFF_ABCD)=21554
|
||||
print sint(Binary.Neg(0xFFFF_ABCD&)+ uint(0xFFFF_ABCD&))=sint(Binary.Neg(0))
|
||||
// signed 0xFFFF_ABCD& has same bits as unsigned 0xFFFF_ABCD,
|
||||
// but have different value as used in calculations
|
||||
print Binary.Neg(0xFFFF_ABCD&)=Binary.Not(0xFFFF_ABCD), 0xFFFF_ABCD&<>0xFFFF_ABCD
|
||||
print Binary.Neg(0x0FFF_ABCD&)=Binary.Not(0x0FFF_ABCD), 0xFFFF_ABCD&<>0xFFFF_ABCD
|
||||
// Add (modulo 32), x unsigned and add a negate signed (converted to unsigned)
|
||||
print binary.add(x, binary.neg(y), 1)=8 ' 10 - 2 =12
|
||||
print binary.add(x, binary.neg(-y), 1)=12 ' 10 - - 2 = 12
|
||||
print sint(binary.neg(x))=-11, binary.neg(x)=binary.not(x)
|
||||
}
|
||||
binary_ops
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
proc bitwise(a, b) =
|
||||
proc bitwise[T: SomeInteger](a, b: T) =
|
||||
echo "a and b: " , a and b
|
||||
echo "a or b: ", a or b
|
||||
echo "a xor b: ", a xor b
|
||||
|
|
|
|||
|
|
@ -9,7 +9,8 @@ sub int-bits (Int $a, Int $b) {
|
|||
say '';
|
||||
say_bit "$a", $a;
|
||||
say '';
|
||||
say_bit "2's complement $a", +^$a;
|
||||
say_bit "1's complement (not) $a", +^$a;
|
||||
say_bit "2's complement $a", +^$a + 1;
|
||||
say_bit "$a and $b", $a +& $b;
|
||||
say_bit "$a or $b", $a +| $b;
|
||||
say_bit "$a xor $b", $a +^ $b;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue