Data update

This commit is contained in:
Ingy döt Net 2026-04-30 12:34:36 -04:00
parent 4bb20c9b71
commit cbaf4c4b64
12390 changed files with 318560 additions and 27248 deletions

View file

@ -0,0 +1,13 @@
with ada.text_io; use ada.text_io;
procedure binary is
bit : array (0..1) of character := ('0','1');
function bin_image (n : Natural) return string is
(if n < 2 then (1 => bit (n)) else bin_image (n / 2) & bit (n mod 2));
test_values : array (1..3) of Natural := (5,50,9000);
begin
for test of test_values loop
put_line ("Output for" & test'img & " is " & bin_image (test));
end loop;
end binary;

View file

@ -0,0 +1,15 @@
ConsoleWrite(IntToBin(50) & @CRLF)
Func IntToBin($iInt)
$Stack = ObjCreate("System.Collections.Stack")
Local $b = -1, $r = ""
While $iInt <> 0
$b = Mod($iInt, 2)
$iInt = INT($iInt/2)
$Stack.Push ($b)
WEnd
For $i = 1 TO $Stack.Count
$r &= $Stack.Pop
Next
Return $r
EndFunc ;==>IntToBin

View file

@ -0,0 +1,17 @@
import ballerina/io;
function bin(int number) returns string {
int n = number;
string out = "";
while n > 0 {
out = (n % 2).toString() + out;
n /= 2;
}
return out;
}
public function main() {
foreach int i in [5, 50, 9000] {
io:println(bin(i));
}
}

View file

@ -0,0 +1,41 @@
(let ((div2 (lambda (n)
(n (lambda (x)
(x (lambda (so-far odd?)
(odd?
;; lambda (p) here and after is inlined cons
(lambda (p)
(p
;; Inlined successor
(lambda (f x)
(f (so-far f x)))
nil))
;; cons so-far t
(lambda (p) (p so-far t))))))
(lambda (p) (p 0 nil)))))
(fixpoint-combinator2
#+nil
(lambda (g)
(let ((inner (lambda (x) (g (x x)))))
(inner inner)))
(lambda (f)
(let ((inner (lambda (x)
(f (lambda (y z)
(x x y z))))))
(inner inner))))
(ascii-zero (lambda (f)
(2 2 2 (3 f))))
(ascii-one (lambda (f x)
(f (ascii-zero f x))))
(binary (fixpoint-combinator2
(lambda (recur acc n)
((div2 n)
(lambda (res rem)
(let ((todigit (lambda (x)
(x ascii-one ascii-zero))))
(res
(lambda (x)
;; cons ascii acc
(recur (lambda (p) (p (todigit rem) acc)) res))
;; cons ascii acc
(lambda (p) (p (todigit rem) acc))))))))))
(binary nil))

View file

@ -0,0 +1,35 @@
(let ((div2 (lambda (n)
(n (lambda (x)
(x (lambda (so-far odd?)
(odd?
;; lambda (p) here and after is inlined cons
(lambda (p)
(p
;; Inlined successor
(lambda (f x)
(f (so-far f x)))
nil))
;; cons so-far t
(lambda (p) (p so-far t))))))
(lambda (p) (p 0 nil)))))
(fixpoint-combinator2
#+nil
(lambda (g)
(let ((inner (lambda (x) (g (x x)))))
(inner inner)))
(lambda (f)
(let ((inner (lambda (x)
(f (lambda (y z)
(x x y z))))))
(inner inner))))
(binary (fixpoint-combinator2
(lambda (recur acc n)
((div2 n)
(lambda (res rem)
(res
(lambda (x)
;; cons bool acc
(recur (lambda (p) (p rem acc)) res))
;; cons bool acc
(lambda (p) (p rem acc)))))))))
(binary nil))

View file

@ -0,0 +1,26 @@
IDENTIFICATION DIVISION.
PROGRAM-ID. SAMPLE.
DATA DIVISION.
WORKING-STORAGE SECTION.
01 binary_number pic X(21).
01 str pic X(21).
01 binary_digit pic X.
01 digit pic 9.
01 n pic 9(7).
01 nstr pic X(7).
PROCEDURE DIVISION.
accept nstr
move nstr to n
perform until n equal 0
divide n by 2 giving n remainder digit
move digit to binary_digit
string binary_digit DELIMITED BY SIZE
binary_number DELIMITED BY SPACE
into str
move str to binary_number
end-perform.
display binary_number
stop run.

View file

@ -0,0 +1,27 @@
IDENTIFICATION DIVISION.
PROGRAM-ID. binary-conversion.
DATA DIVISION.
WORKING-STORAGE SECTION.
01 binary-number pic X(21).
01 digit pic 9.
01 n pic 9(7).
01 nstr pic X(7).
01 ptr pic 99.
PROCEDURE DIVISION.
display "Number: " with no advancing.
accept nstr.
move nstr to n.
move zeroes to binary-number.
move length binary-number to ptr.
perform until n equal 0
divide n by 2 giving n remainder digit
move digit to binary-number(ptr:1)
subtract 1 from ptr
if ptr < 1
exit perform
end-if
end-perform.
display binary-number.
stop run.

View file

@ -0,0 +1,10 @@
(defun int-to-binary (val)
(let ((x val) (result ""))
(while (> x 0)
(setq result (concat (number-to-string (% x 2)) result))
(setq x (/ x 2)))
result))
(message "5 => %s" (int-to-binary 5))
(message "50 => %s" (int-to-binary 50))
(message "9000 => %s" (int-to-binary 9000))

View file

@ -0,0 +1,13 @@
function toBinary(integer i)
sequence s
s = {}
while i do
s = prepend(s, '0'+and_bits(i,1))
i = floor(i/2)
end while
return s
end function
puts(1, toBinary(5) & '\n')
puts(1, toBinary(50) & '\n')
puts(1, toBinary(9000) & '\n')

View file

@ -0,0 +1,16 @@
include std/math.e
include std/convert.e
function Bin(integer n, sequence s = "")
if n > 0 then
return Bin(floor(n/2),(mod(n,2) + #30) & s)
end if
if length(s) = 0 then
return to_integer("0")
end if
return to_integer(s)
end function
printf(1, "%d\n", Bin(5))
printf(1, "%d\n", Bin(50))
printf(1, "%d\n", Bin(9000))

View file

@ -0,0 +1,9 @@
import gleam/format
import gleam/list
pub fn main() -> Nil {
// Using format library: https://hexdocs.pm/format/gleam/format.html
[5, 50, 9000]
|> list.map(format.printf("~.2B~n", _))
Nil
}

View file

@ -0,0 +1,15 @@
class Main {
static public function main() {
var integers = [5, 50, 9000];
for (i in integers) {
var bin = "";
while (i > 1) {
bin = (i % 2) + bin;
i = Std.int(i / 2);
}
bin = i + bin;
trace(bin);
}
}
}

View file

@ -0,0 +1 @@
@(5,50,900) | foreach-object { [Convert]::ToString($_,2) }

View file

@ -0,0 +1,24 @@
-- 12 Sep 2025
include Setting
numeric digits 100
say 'BINARY DIGITS'
say version
say
say left('Decimal',9) '= Binary'
call Task 0
call Task 5
call Task 50
call Task 9000
call Task 999999999
call Task 1e30
exit
Task:
arg xx
-- Built-in Decimal2Hex -> Hex2Binary -> Normalize
say left(xx,9) '=' X2B(D2X(xx))
say left(xx,9) '=' X2B(D2X(xx))+0
return 0
include Math

View file

@ -0,0 +1,5 @@
foreach number [5 50 9000] [
;; any returns first not false value, used to cut leading zeroes
binstr: copy any [find enbase/flat to binary! number 2 #"1" #"0"]
print reduce [ pad number -5 binstr ]
]

View file

@ -0,0 +1,23 @@
Option Explicit
Dim bin
bin=Array(" "," I"," I "," II"," I "," I I"," II "," III","I ","I I","I I ","I II"," I ","II I","III ","IIII")
Function num2bin(n)
Dim s,i,n1,n2
s=Hex(n)
For i=1 To Len(s)
n1=Asc(Mid(s,i,1))
If n1>64 Then n2=n1-55 Else n2=n1-48
num2bin=num2bin & bin(n2)
Next
num2bin=Replace(Replace(LTrim(num2bin)," ","0"),"I",1)
End Function
Sub print(s):
On Error Resume Next
WScript.stdout.WriteLine (s)
If err= &h80070006& Then WScript.Echo " Please run this script with CScript": WScript.quit
End Sub
print num2bin(5)
print num2bin(50)
print num2bin(9000)