How to resolve the algorithm Binary digits step by step in the REXX programming language
Published on 12 May 2024 09:40 PM
How to resolve the algorithm Binary digits step by step in the REXX programming language
Table of Contents
Problem Statement
Create and display the sequence of binary digits for a given non-negative integer. The results can be achieved using built-in radix functions within the language (if these are available), or alternatively a user defined function can be used. The output produced should consist just of the binary digits of each number followed by a newline. There should be no other whitespace, radix or sign markers in the produced output, and leading zeros should not appear in the results.
Let's start with the solution:
Step by Step solution about How to resolve the algorithm Binary digits step by step in the REXX programming language
Source code in the rexx programming language
/*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. */
/*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. */
/*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. */
/*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. */
You may also check:How to resolve the algorithm Boolean values step by step in the C programming language
You may also check:How to resolve the algorithm Calculating the value of e step by step in the Go programming language
You may also check:How to resolve the algorithm Count in octal step by step in the Maple programming language
You may also check:How to resolve the algorithm Even or odd step by step in the LiveCode programming language
You may also check:How to resolve the algorithm Execute a system command step by step in the Run BASIC programming language