How to resolve the algorithm Binary digits step by step in the Oberon-2 programming language

Published on 12 May 2024 09:40 PM

How to resolve the algorithm Binary digits step by step in the Oberon-2 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 Oberon-2 programming language

Source code in the oberon-2 programming language

MODULE BinaryDigits;
IMPORT  Out;
 
  PROCEDURE OutBin(x: INTEGER);
  BEGIN
    IF x > 1 THEN OutBin(x DIV 2) END;
    Out.Int(x MOD 2, 1);
  END OutBin;
 
 
BEGIN
  OutBin(0); Out.Ln;
  OutBin(1); Out.Ln;
  OutBin(2); Out.Ln;
  OutBin(3); Out.Ln;
  OutBin(42); Out.Ln;
END BinaryDigits.

  

You may also check:How to resolve the algorithm Bitmap/Write a PPM file step by step in the Kotlin programming language
You may also check:How to resolve the algorithm Guess the number/With feedback step by step in the COBOL programming language
You may also check:How to resolve the algorithm Hello world/Text step by step in the Kabap programming language
You may also check:How to resolve the algorithm Bulls and cows step by step in the FOCAL programming language
You may also check:How to resolve the algorithm Discordian date step by step in the C# programming language