Sponsored Content
Full Discussion: 20th based convertor
Top Forums Shell Programming and Scripting 20th based convertor Post 302335261 by Dax01 on Saturday 18th of July 2009 03:15:02 AM
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
 

5 More Discussions You Might Find Interesting

1. 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

2. 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

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. 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

5. 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
ZIPARCHIVE.OPEN(3)							 1							ZIPARCHIVE.OPEN(3)

ZipArchive::open - Open a ZIP file archive

SYNOPSIS
mixed ZipArchive::open (string $filename, [int $flags]) DESCRIPTION
Opens a new zip archive for reading, writing or modifying. PARAMETERS
o $filename - The file name of the ZIP archive to open. o $flags - The mode to use to open the archive. o ZipArchive::OVERWRITE o ZipArchive::CREATE o ZipArchive::EXCL o ZipArchive::CHECKCONS RETURN VALUES
o $Error codes - Returns TRUE on success or the error code. o ZipArchive::ER_EXISTS File already exists. o ZipArchive::ER_INCONS Zip archive inconsistent. o ZipArchive::ER_INVAL Invalid argument. o ZipArchive::ER_MEMORY Malloc failure. o ZipArchive::ER_NOENT No such file. o ZipArchive::ER_NOZIP Not a zip archive. o ZipArchive::ER_OPEN Can't open file. o ZipArchive::ER_READ Read error. o ZipArchive::ER_SEEK Seek error. EXAMPLES
Example #1 Open and extract <?php $zip = new ZipArchive; $res = $zip->open('test.zip'); if ($res === TRUE) { echo 'ok'; $zip->extractTo('test'); $zip->close(); } else { echo 'failed, code:' . $res; } ?> Example #2 Create an archive <?php $zip = new ZipArchive; $res = $zip->open('test.zip', ZipArchive::CREATE); if ($res === TRUE) { $zip->addFromString('test.txt', 'file content goes here'); $zip->addFile('data.txt', 'entryname.txt'); $zip->close(); echo 'ok'; } else { echo 'failed'; } ?> PHP Documentation Group ZIPARCHIVE.OPEN(3)
All times are GMT -4. The time now is 08:33 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy