How to resolve the algorithm Binary digits step by step in the VBScript programming language

Published on 12 May 2024 09:40 PM

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

Source code in the vbscript programming language

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)

  

You may also check:How to resolve the algorithm Langton's ant step by step in the BQN programming language
You may also check:How to resolve the algorithm Spiral matrix step by step in the Arturo programming language
You may also check:How to resolve the algorithm Mutual recursion step by step in the R programming language
You may also check:How to resolve the algorithm Rename a file step by step in the Fortran programming language
You may also check:How to resolve the algorithm Polymorphic copy step by step in the NetRexx programming language