20th based convertor


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting 20th based convertor
# 1  
Old 07-18-2009
20th based convertor

Hi, I'm new at Linux shell programming so I could use some help. I need to make a 20thdecimal convertor. Is just like hexadecimal, the only difference is that hexadecimal goes from 1-9 and A-F, and I need this one to go from 1-9 and A-J.
I got some already but I get endless loop, please take a look.

Code:
echo -n "insert number to be converted: " 
read decimal 
 
until [ $decimal -eq 0 ] 
do 
div=`echo $decimal /20 | bc` 
res=`echo "$decimal-$div * 20" | bc` 
echo $res $div 
done

At this point I get the two number that I need, then I just add some labels to let it know that A= 11, B= 12, etc. The thing is I cannot stop the loopSmilieAny ideas aprecciated.

I used this Hexadecimal convertor as started and just changed the base from 16 (hexadecimal) to 20 (the one I desire) on lines 6,7.

Code:
echo -n "numbers to be converted: " 
read decimal 
 
while [ $decimal -gt 0 ] 
do 
div=`echo $decimal /16 | bc` 
res=`echo "$decimal-$div * 16" | bc` decimal=$div 
if [ $res -eq 10 ] ; then 
res=a 
if [ $res -eq 11 ] ; then 
res=b 
elif [ $res -lt 9 ] ; then 
res= $res 
fi 
hex= $res $div 
echo $hex


Last edited by DukeNuke2; 07-18-2009 at 04:19 AM.. Reason: added code tags
# 2  
Old 07-18-2009
To keep the forums high quality for all users, please take the time to format your posts correctly.

First of all, use Code Tags when you post any code or data samples so others can easily read your code. You can easily do this by highlighting your code and then clicking on the # in the editing menu. (You can also type code tags [code] and [/code] by hand.)

Second, avoid adding color or different fonts and font size to your posts. Selective use of color to highlight a single word or phrase can be useful at times, but using color, in general, makes the forums harder to read, especially bright colors like red.

Third, be careful when you cut-and-paste, edit any odd characters and make sure all links are working property.

Thank You.

The UNIX and Linux Forums
# 3  
Old 07-18-2009
Sorry about that. Seems like no one is up to it, I have till tomorrow 11:59pm so....bump please? =(
I'm tired of thinking by myself.
# 4  
Old 07-18-2009
the weekend isn't the best time for your question... this is mostly a very professional board and our members are online during workdays. i guess the weekend is for other stuff Smilie. so please be patient and don't bump up your posts because this is against the rules also!
# 5  
Old 07-18-2009
Where is that $decimal value is getting decremented?
# 6  
Old 07-19-2009
Simple to do if you can use ksh93
Code:
echo -n "insert number to be converted: "
read dec

typeset -i20 num=dec

echo ${num:3}

# 7  
Old 07-19-2009
Sorry again for the bump. Matrix I didn't quite get your question, could you explain it a little better please? And murphy I'm gonna try your idea now, but could you explain me the function of the commands? Cause my teacher might ask what the shell I did and if I don't know I'm done for.

(Note that when I said "what the shell I did" I really meant "what the h*ll I did", just a senseless Linux users joke. I'm not sure if you can say that word, want not brake the rules again)

EDIT:This ksh93 you talk about, do I have to download it and install it? Cause I'm out of home now and I'm using my ubuntu cd as live. :S

EDIT2: Just read the rules and found out this is no place for homework post neither...my grave is digged.

---------- Post updated at 05:37 PM ---------- Previous update was at 07:59 AM ----------

For the love of God, won't anyone help me? I could be a great open source programmer on day but I gotta get this step done first. My time is running out, 5 hours left...and I just need to get pass that loop!

---------- Post updated at 08:40 PM ---------- Previous update was at 05:37 PM ----------

Here guys, I finished, just 3 hours left lol. Thanks for your help Murphy and Matrix. Won't flame people who didn't help me cause its against the rules (hard to resist). Enjoy trying it, its kinda fun. I'll tell my friends I beated Unix forums.

Code:
echo    "                     .: Bienvenido a mi examen completivo:. "  
 
echo"" 
 
echo -n "Cantidad que desea convertir: " 
read op1 
 
until [ $op1 -eq 0 ] 
do 
op2=`echo $op1 / 20 | bc` 
op3=`echo "$op1 - $op2 * 20" | bc` 
op1=$op2 
 
case $op3 in 
10) op3=A 
;; 
11) op3=B 
;; 
12) op3=C 
;; 
13) op3=D 
;; 
14) op3=E 
;; 
15) op3=F 
;; 
16) op3=G 
;; 
17) op3=H 
;; 
18) op3=I 
;; 
19) op3=J 
esac 
 
final=$final$op3 
done 
echo $final


Last edited by Dax01; 07-19-2009 at 12:09 PM.. Reason: did not work
Login or Register to Ask a Question

Previous Thread | Next Thread

5 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Searching for bash to cshell convertor

Hi ,I have seen this comverters before ,but I was searching today and I can not find them .Is anybody used them before .Any recomendations Thanks (5 Replies)
Discussion started by: lio123
5 Replies

2. UNIX for Dummies Questions & Answers

Script ran by job scheduler fails from the 15th to the 20th of the month

Hi, I have a script that finds the application logs from the previous day and sends it to another server via ftp. The code is something like this: yest_date=`TZ=CST+24 date "+%b %d"` logdir=/app/logs logs=app*.log tmpdir=/tmp cd $logdir for i in `ls -1 $logs` do chkstr=`ls -1l $i | grep... (2 Replies)
Discussion started by: tatchel
2 Replies

3. UNIX and Linux Applications

web to wap convertor

cld someone suggest a good web to wap convertor (1 Reply)
Discussion started by: viapillai
1 Replies

4. Programming

Binary to Text Convertor

Hey Im starting out in C just recently and Im needing a string that converts binary to text, The only way i know of doing this without knowledge of C entirely. Is Making a sorta of library of the entire alphabet in binary for the program to select the text from it to display a sentence. If that... (2 Replies)
Discussion started by: 01doublehelix10
2 Replies

5. Shell Programming and Scripting

Perl to C convertor

Is there one out there that supports Perl/Tk ??? (5 Replies)
Discussion started by: perleo
5 Replies
Login or Register to Ask a Question