Another update from ingydotnet^djgoku

This commit is contained in:
Ingy döt Net 2015-11-18 06:14:39 +00:00
parent 91df62d461
commit 948b86eafa
7604 changed files with 108452 additions and 22726 deletions

View file

@ -1,20 +1,20 @@
#define system.
#define extensions.
#symbol bitwiseTest = (:x:y)
[
console write:x write:" and " write:y write:" = " writeLine:(x and:y).
console write:x write:" or " write:y write:" = " writeLine:(x or:y).
console write:x write:" xor " write:y write:" = " writeLine:(x xor:y).
console write:"not " write:x write:" = " writeLine:(x not).
console write:x write:" shr " write:y write:" = " writeLine:(x shift &index:(y int)).
console write:x write:" shl " write:y write:" = " writeLine:(x shift &index:(y negative int)).
].
#class(extension) testOp
{
#method bitwiseTest : y
[
console writeLine:self:" and ":y:" = ":(self and:y).
console writeLine:self:" or ":y:" = ":(self or:y).
console writeLine:self:" xor ":y:" = ":(self xor:y).
console writeLine:"not ":self:" = ":(self not).
console writeLine:self:" shr ":y:" = ":(self shift &index:y).
console writeLine:self:" shl ":y:" = ":(self shift &index:(y negative)).
]
}
#symbol program =
[
#var a := consoleEx readLine:(Integer new).
#var b := consoleEx readLine:(Integer new).
bitwiseTest:a:b.
console readLine:(Integer new) bitwiseTest:(console readLine:(Integer new)).
].

View file

@ -0,0 +1,22 @@
defmodule Bitwise_operation do
use Bitwise
def test(a \\ 255, b \\ 170, c \\ 2) do
IO.puts "Bitwise function:"
IO.puts "band(#{a}, #{b}) = #{band(a, b)}"
IO.puts "bor(#{a}, #{b}) = #{bor(a, b)}"
IO.puts "bxor(#{a}, #{b}) = #{bxor(a, b)}"
IO.puts "bnot(#{a}) = #{bnot(a)}"
IO.puts "bsl(#{a}, #{c}) = #{bsl(a, c)}"
IO.puts "bsr(#{a}, #{c}) = #{bsr(a, c)}"
IO.puts "\nBitwise as operator:"
IO.puts "#{a} &&& #{b} = #{a &&& b}"
IO.puts "#{a} ||| #{b} = #{a ||| b}"
IO.puts "#{a} ^^^ #{b} = #{a ^^^ b}"
IO.puts "~~~#{a} = #{~~~a}"
IO.puts "#{a} <<< #{c} = #{a <<< c}"
IO.puts "#{a} >>> #{c} = #{a >>> c}"
end
end
Bitwise_operation.test

View file

@ -2,7 +2,7 @@ constant MAXINT = uint.Range.max;
constant BITS = MAXINT.base(2).chars;
# define rotate ops for the fun of it
multi sub infix:<>(Int:D \a, Int:D \b) { :2[(a +& MAXINT).polymod(2 xx BITS-1).rotate(b).reverse] }
multi sub infix:<>(Int:D \a, Int:D \b) { :2[(a +& MAXINT).polymod(2 xx BITS-1).list.rotate(b).reverse] }
multi sub infix:<>(Int:D \a, Int:D \b) { :2[(a +& MAXINT).polymod(2 xx BITS-1).reverse.rotate(b)] }
sub int-bits (Int $a, Int $b) {

View file

@ -0,0 +1,4 @@
$X -band $Y
$X -bor $Y
$X -bxor $Y
-bnot $X

View file

@ -0,0 +1,6 @@
$X -shl $Y
# Arithmetic right shift
$X -shr $Y
# Requires quite a stretch of the imagination to call this "native" support of right rotate, but it works
[System.Security.Cryptography.SHA256Managed].GetMethod('RotateRight', 'NonPublic, Static', $null, @([UInt32], [Int32]), $null).Invoke($null, @([uint32]$X, $Y))

View file

@ -1,12 +1,12 @@
fn main() {
let a: u8 = 105;
let b: u8 = 91;
println!("a = {:0>8t}", a);
println!("b = {:0>8t}", b);
println!("a | b = {:0>8t}", a | b);
println!("a & b = {:0>8t}", a & b);
println!("a ^ b = {:0>8t}", a ^ b);
println!("!a = {:0>8t}", !a);
println!("a << 3 = {:0>8t}", a >> 3);
println!("a >> 3 = {:0>8t}", a << 3);
println!("a = {:0>8b}", a);
println!("b = {:0>8b}", b);
println!("a | b = {:0>8b}", a | b);
println!("a & b = {:0>8b}", a & b);
println!("a ^ b = {:0>8b}", a ^ b);
println!("!a = {:0>8b}", !a);
println!("a << 3 = {:0>8b}", a << 3);
println!("a >> 3 = {:0>8b}", a >> 3);
}