Decimal to BCD (Binary Coded Decimal)

Use and complete the template provided. The entire template must be completed. If you don't, your post may be deleted!

  1. The problem statement, all variables and given/known data:

Design an algorithm that accepts an input a decimal number and converts it into BCD (Binary Coded Decimal) representation. Also, draw its Flow Chart. :frowning:

  1. Relevant commands, code, scripts, algorithms:

UNIX

  1. The attempts at a solution (include all code and scripts):

1:[enter the number]
read n
2:[find the length]
leng=length(n)
a=0
3:[perform the conversion]

for i=0 to leng-1
n1=n1%2[to take the right most digit]

  for j=0 to 3
     n2=n1%2[to take the reminder]
     ans[a]=n2
     a\+\+
     n1=n1/2
  end for

n=n/10[to take the number except the right digit]
end for

[print the number]

fori=a-1 to 0
print ans
[i]end

  1. Complete Name of School (University), City (State), Country, Name of Professor, and Course Number (Link to Course):

IGNOU / NewDelhi / BCA

Note: Without school/professor/course information, you will be banned if you post here! You must complete the entire template (not just parts of it).

You can use the bc command to change bases. man bc to read up on obase.

#!/bin/bash

echo "Enter in an interger: "
read value
echo -n "Your result: "
echo "-obase=2; $value" | bc

You need to provide complete information or you cannot post homework here:

  1. Complete Name of School (University), City (State), Country, Name of Professor, and Course Number (Link to Course):