Data update
This commit is contained in:
parent
5150844a7d
commit
4bb20c9b71
7735 changed files with 38060 additions and 199180 deletions
|
|
@ -1,13 +0,0 @@
|
|||
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;
|
||||
|
|
@ -1,3 +1,3 @@
|
|||
print as.binary 5
|
||||
print as.binary 50
|
||||
print as.binary 9000
|
||||
print to :string .format:".b" 5
|
||||
print to :string .format:".b" 50
|
||||
print to :string .format:".b" 9000
|
||||
|
|
|
|||
|
|
@ -1,15 +0,0 @@
|
|||
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
|
||||
|
|
@ -1,14 +1,6 @@
|
|||
#include <iostream>
|
||||
#include <bitset>
|
||||
void printBits(int n) { // Use int like most programming languages.
|
||||
int iExp = 0; // Bit-length
|
||||
while (n >> iExp) ++iExp; // Could use template <log(x)*1.44269504088896340736>
|
||||
for (int at = iExp - 1; at >= 0; at--) // Reverse iter from the bit-length to 0 - msb is at end
|
||||
std::cout << std::bitset<32>(n)[at]; // Show 1's, show lsb, hide leading zeros
|
||||
std::cout << '\n';
|
||||
#include <print>
|
||||
int main() {
|
||||
std::println("{:b}", 5);
|
||||
std::println("{:b}", 50);
|
||||
std::println("{:b}", 9000);
|
||||
}
|
||||
int main(int argc, char* argv[]) {
|
||||
printBits(5);
|
||||
printBits(50);
|
||||
printBits(9000);
|
||||
} // for testing with n=0 printBits<32>(0);
|
||||
|
|
|
|||
|
|
@ -1,8 +0,0 @@
|
|||
#include <iostream>
|
||||
int main(int argc, char* argv[]) {
|
||||
unsigned int in[] = {5, 50, 9000}; // Use int like most programming languages
|
||||
for (int i = 0; i < 3; i++) // Use all inputs
|
||||
for (int at = 31; at >= 0; at--) // reverse iteration from the max bit-length to 0, because msb is at the end
|
||||
if (int b = (in[i] >> at)) // skip leading zeros. Start output when significant bits are set
|
||||
std::cout << ('0' + b & 1) << (!at ? "\n": ""); // '0' or '1'. Add EOL if last bit of num
|
||||
}
|
||||
|
|
@ -1,7 +0,0 @@
|
|||
#include <iostream>
|
||||
int main(int argc, char* argv[]) { // Usage: program.exe 5 50 9000
|
||||
for (int i = 1; i < argc; i++) // argv[0] is program name
|
||||
for (int at = 31; at >= 0; at--) // reverse iteration from the max bit-length to 0, because msb is at the end
|
||||
if (int b = (atoi(argv[i]) >> at)) // skip leading zeros
|
||||
std::cout << ('0' + b & 1) << (!at ? "\n": ""); // '0' or '1'. Add EOL if last bit of num
|
||||
}
|
||||
|
|
@ -1,11 +0,0 @@
|
|||
#include <iostream>
|
||||
|
||||
std::string binary(int n) {
|
||||
return n == 0 ? "" : binary(n >> 1) + std::to_string(n & 1);
|
||||
}
|
||||
|
||||
int main(int argc, char* argv[]) {
|
||||
for (int i = 1; i < argc; ++i) {
|
||||
std::cout << binary(std::stoi(argv[i])) << std::endl;
|
||||
}
|
||||
}
|
||||
|
|
@ -1,26 +0,0 @@
|
|||
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.
|
||||
|
|
@ -1,27 +0,0 @@
|
|||
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.
|
||||
|
|
@ -1,7 +1,7 @@
|
|||
import system'routines;
|
||||
import extensions;
|
||||
|
||||
public program()
|
||||
public Program()
|
||||
{
|
||||
new int[]{5,50,9000}.forEach::(n)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -1,10 +0,0 @@
|
|||
(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))
|
||||
|
|
@ -1,13 +0,0 @@
|
|||
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')
|
||||
|
|
@ -1,16 +0,0 @@
|
|||
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))
|
||||
|
|
@ -1,15 +0,0 @@
|
|||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1 +0,0 @@
|
|||
@(5,50,900) | foreach-object { [Convert]::ToString($_,2) }
|
||||
|
|
@ -1,11 +0,0 @@
|
|||
/*REXX program to convert several decimal numbers to binary (or base 2). */
|
||||
numeric digits 1000 /*ensure we can handle larger numbers. */
|
||||
@.=; @.1= 0
|
||||
@.2= 5
|
||||
@.3= 50
|
||||
@.4= 9000
|
||||
|
||||
do j=1 while @.j\=='' /*compute until a NULL value is found.*/
|
||||
y=x2b( d2x(@.j) ) + 0 /*force removal of extra leading zeroes*/
|
||||
say right(@.j,20) 'decimal, and in binary:' y /*display the number to the terminal. */
|
||||
end /*j*/ /*stick a fork in it, we're all done. */
|
||||
|
|
@ -1,11 +0,0 @@
|
|||
/*REXX program to convert several decimal numbers to binary (or base 2). */
|
||||
@.=; @.1= 0
|
||||
@.2= 5
|
||||
@.3= 50
|
||||
@.4= 9000
|
||||
|
||||
do j=1 while @.j\=='' /*compute until a NULL value is found.*/
|
||||
y=strip( x2b( d2x( @.j )), 'L', 0) /*force removal of all leading zeroes.*/
|
||||
if y=='' then y=0 /*handle the special case of 0 (zero).*/
|
||||
say right(@.j,20) 'decimal, and in binary:' y /*display the number to the terminal. */
|
||||
end /*j*/ /*stick a fork in it, we're all done. */
|
||||
|
|
@ -1,10 +0,0 @@
|
|||
/*REXX program to convert several decimal numbers to binary (or base 2). */
|
||||
@.=; @.1= 0
|
||||
@.2= 5
|
||||
@.3= 50
|
||||
@.4= 9000
|
||||
|
||||
do j=1 while @.j\=='' /*compute until a NULL value is found.*/
|
||||
y=word( strip( x2b( d2x( @.j )), 'L', 0) 0, 1) /*elides all leading 0s, if null, use 0*/
|
||||
say right(@.j,20) 'decimal, and in binary:' y /*display the number to the terminal. */
|
||||
end /*j*/ /*stick a fork in it, we're all done. */
|
||||
|
|
@ -1,14 +0,0 @@
|
|||
/*REXX program to convert several decimal numbers to binary (or base 2). */
|
||||
numeric digits 200 /*ensure we can handle larger numbers. */
|
||||
@.=; @.1= 0
|
||||
@.2= 5
|
||||
@.3= 50
|
||||
@.4= 9000
|
||||
@.5=423785674235000123456789
|
||||
@.6= 1e138 /*one quinquaquadragintillion ugh.*/
|
||||
|
||||
do j=1 while @.j\=='' /*compute until a NULL value is found.*/
|
||||
y=strip( x2b( d2x( @.j )), 'L', 0) /*force removal of all leading zeroes.*/
|
||||
if y=='' then y=0 /*handle the special case of 0 (zero).*/
|
||||
say y /*display binary number to the terminal*/
|
||||
end /*j*/ /*stick a fork in it, we're all done. */
|
||||
|
|
@ -1,23 +0,0 @@
|
|||
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)
|
||||
Loading…
Add table
Add a link
Reference in a new issue