This commit is contained in:
Ingy döt Net 2013-06-05 21:47:54 +00:00
parent 1f1ad49427
commit 6f050a029e
2496 changed files with 37609 additions and 3031 deletions

View file

@ -0,0 +1,8 @@
o_xinteger(2, 0);
o_byte('\n');
o_xinteger(2, 5);
o_byte('\n');
o_xinteger(2, 50);
o_byte('\n');
o_xinteger(2, 9000);
o_byte('\n');

View file

@ -0,0 +1,17 @@
( dec2bin
= bit bits
. :?bits
& whl
' ( !arg:>0
& mod$(!arg,2):?bit
& div$(!arg,2):?arg
& !bit !bits:?bits
)
& (str$!bits:~|0)
)
& 0 5 50 9000 423785674235000123456789:?numbers
& whl
' ( !numbers:%?dec ?numbers
& put$(str$(!dec ":\n" dec2bin$!dec \n\n))
)
;

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,57 @@
!-*- mode: compilation; default-directory: "/tmp/" -*-
!Compilation started at Sun May 19 23:14:14
!
!a=./F && make $a && $a < unixdict.txt
!f95 -Wall -ffree-form F.F -o F
!101
!110010
!10001100101000
!
!Compilation finished at Sun May 19 23:14:14
!
!
! tobin=: -.&' '@":@#:
! tobin 5
!101
! tobin 50
!110010
! tobin 9000
!10001100101000
program bits
implicit none
integer, dimension(3) :: a
integer :: i
data a/5,50,9000/
do i = 1, 3
call s(a(i))
enddo
contains
subroutine s(a)
integer, intent(in) :: a
integer :: i
if (a .eq. 0) then
write(6,'(a)')'0'
return
endif
do i = 31, 0, -1
if (btest(a, i)) exit
enddo
do while (0 .lt. i)
if (btest(a, i)) then
write(6,'(a)',advance='no')'1'
else
write(6,'(a)',advance='no')'0'
endif
i = i-1
enddo
if (btest(a, i)) then
write(6,'(a)')'1'
else
write(6,'(a)')'0'
endif
end subroutine s
end program bits

View file

@ -1,12 +1,18 @@
/* NetRexx */
options replace format comments java crossref symbols nobinary
options replace format comments java crossref savelog symbols nobinary
nums = [5, 50, 9000]
loop n_ = 0 to nums.length - 1
v_ = nums[n_]
say v_.d2x.x2b.strip('L', 0)
end n_
runSample(arg)
return
method getBinaryDigits(nr) public static
bd = nr.d2x.x2b.strip('L', 0)
if bd.length = 0 then bd = 0
return bd
method runSample(arg) public static
parse arg list
if list = '' then list = '0 5 50 9000'
loop n_ = 1 to list.words
w_ = list.word(n_)
say w_.right(20)':' getBinaryDigits(w_)
end n_

View file

@ -1 +1 @@
put list (25) (B);
put edit (25) (B);

View file

@ -0,0 +1,2 @@
binary(X) :- format('~2r~n', [X]).
main :- maplist(binary, [5,50,9000]), halt.

View file

@ -1,11 +1,9 @@
/*REXX program demonstrates converting decimal ───► binary. */
numeric digits 1000
x.1 = 0
x.2 = 5
x.3 = 50
x.4 = 9000
do j=1 for 4
y = x2b(d2x(x.j)) + 0
say right(x.j,20) 'decimal, and in binary:' y

View file

@ -1,10 +1,8 @@
/*REXX program demonstrates converting decimal ───► binary. */
x.1 = 0
x.2 = 5
x.3 = 50
x.4 = 9000
do j=1 for 4
y = strip( x2b( d2x( x.j )), 'L', 0)
if y=='' then y=0

View file

@ -1,5 +1,4 @@
/*REXX program demonstrates converting decimal ───► binary. */
x.1 = 0
x.2 = 5
x.3 = 50

View file

@ -1,3 +1,5 @@
#lang racket
(for ([i 16])
(displayln (number->string i 2)))
;; Option 1: binary formatter
(for ([i 16]) (printf "~b\n" i))
;; Option 2: explicit conversion
(for ([i 16]) (displayln (number->string i 2)))