This commit is contained in:
Ingy döt Net 2013-10-27 22:24:23 +00:00
parent 6f050a029e
commit 776bba907c
3887 changed files with 59894 additions and 7280 deletions

View file

@ -1,4 +1,4 @@
IDENTIFICATION DIVISION.
IDENTIFICATION DIVISION.
PROGRAM-ID. SAMPLE.
DATA DIVISION.

View file

@ -0,0 +1,15 @@
MODULE BinaryDigits;
IMPORT StdLog,Strings;
PROCEDURE Do*;
VAR
str : ARRAY 33 OF CHAR;
BEGIN
Strings.IntToStringForm(5,2,32,'0',FALSE,str);
StdLog.Int(5);StdLog.String(":> " + str);StdLog.Ln;
Strings.IntToStringForm(50,2,32,'0',FALSE,str);
StdLog.Int(50);StdLog.String(":> " + str);StdLog.Ln;
Strings.IntToStringForm(9000,2,32,'0',FALSE,str);
StdLog.Int(9000);StdLog.String(":> " + str);StdLog.Ln;
END Do;
END BinaryDigits.

View file

@ -1,11 +1,11 @@
#define std'dictionary'*.
#define ext'convertors'*.
#define system.
#define extensions.
// --- Program ---
#symbol Program =
#symbol program =
[
'program'output write &numeric:5 &radix:2 &:eintformatter << "%n".
'program'output write &numeric:50 &radix:2 &:eintformatter << "%n".
'program'output write &numeric:9000 &radix:2 &:eintformatter << "%n".
console writeLine:(convertControl toLiteral:5 &radix:2).
console writeLine:(convertControl toLiteral:50 &radix:2).
console writeLine:(convertControl toLiteral:9000 &radix:2).
].

View file

@ -1,4 +1,4 @@
> printf( "%d\n", convert( 50, 'binary' ) );
> convert( 50, 'binary' );
110010
> printf( "%d\n", convert( 9000, 'binary' ) );
> convert( 9000, 'binary' );
10001100101000

View file

@ -1,11 +1,12 @@
/*REXX program demonstrates converting decimal ───► binary. */
numeric digits 1000
x.=
x.1 = 0
x.2 = 5
x.3 = 50
x.4 = 9000
do j=1 for 4
y = x2b(d2x(x.j)) + 0
do j=1 while x.j\=='' /*compute until a NULL is found.*/
y = x2b(d2x(x.j)) + 0 /*force removal of leading zeroes*/
say right(x.j,20) 'decimal, and in binary:' y
end /*j*/
/*stick a fork in it, we're done.*/

View file

@ -1,11 +1,12 @@
/*REXX program demonstrates converting decimal ───► binary. */
x.=
x.1 = 0
x.2 = 5
x.3 = 50
x.4 = 9000
do j=1 for 4
do j=1 while x.j\=='' /*compute until a NULL is found.*/
y = strip( x2b( d2x( x.j )), 'L', 0)
if y=='' then y=0
if y=='' then y=0 /*handle special case of 0 (zero)*/
say right(x.j,20) 'decimal, and in binary:' y
end /*j*/
/*stick a fork in it, we're done.*/

View file

@ -1,9 +1,10 @@
/*REXX program demonstrates converting decimal ───► binary. */
x.1 = 0
x.2 = 5
x.3 = 50
x.4 = 9000
do j=1 for 4
x.=
x.1=0
x.2=5
x.3=50
x.4=9000
do j=1 while x.j\=='' /*compute until a NULL is found.*/
y = word( strip( x2b( d2x( x.j )), 'L', 0) 0, 1)
say right(x.j,20) 'decimal, and in binary:' y
end /*j*/

View file

@ -0,0 +1,16 @@
/*REXX program demonstrates converting decimal ───► binary. */
numeric digits 200
x.=
x.1=0
x.2=5
x.3=50
x.4=9000
x.5=423785674235000123456789
x.6=1e138 /*one quinquaquadragintillion. */
do j=1 while x.j\=='' /*compute until a NULL is found.*/
y = strip( x2b( d2x( x.j )), 'L', 0)
if y=='' then y=0 /*handle special case of 0 (zero)*/
say y
end /*j*/
/*stick a fork in it, we're done.*/

View file

@ -1,3 +1,9 @@
5 toBinaryString // 101
50 toBinaryString // 110010
9000 toBinaryString // 10001100101000
import scala.language.postfixOps
object BinaryDigits {
(5 toBinaryString).reverse.padTo(14, '0').reverse
//> res0: String = 00000000000101
(50 toBinaryString).reverse.padTo(14, '0').reverse
//> res1: String = 00000000110010
(9000 toBinaryString).reverse.padTo(14, '0').reverse
//> res2: String = 10001100101000
}