/****************************************************************************/ // // // +----------------------+ // // | BASE CONVERTER V 2.0 | // // +----------------------+ // // // // Convert a number of any base to a number of the chosen base. Made for // // arytmetic lessons. // // // // compiled with tigcc. // // command line : tigcc -02 chgbase.c // // // // By Stanowski Etienne as IronMan // // If you have any comment : Stan.Etienne@caramail.com // // Date : 19:02 20/10/2000 // // // /****************************************************************************/ * Why nostub mode : ------------------- Nostub mode is better than Doors one, first because the code is smaller, then it can be launched without any kernel (like a CAS function) and finally, status line don't print errors in Doors mode. Yet, you are allowed to compile it in Doors mode if you want (at your own risks : it has not been tested!) You will have to add this line : char _comment[] = "Primes Generator V 1.1 by Stanowki Etienne"; * What is the base of a number : -------------------------------- Common numbers used in Maths are from base 10 as they use 10 digits to be represented : 0,1,2,3,4,5,6,7,8 and 9. It is the same in informatic with binary (base 2) numbers which are numbers represented by only 2 digits : 0 and 1; hexadecimal (base 16) numbers by 16 : 1,2,3,4,5,6,7,8,9,A,B,C,D,E and F. But it is possible to convert numbers from base 10 into base 2, from base 2 into base 10, 10->16, 16->10, 2->16, 16->2... There is an infinity of different bases; the aim of this function is to convert a number of any base into a number of a chosen base. (src is easy to understand but it may exist better or faster way to convert as it is my own way to convert numbers). Signed conversions exists only in informatc, with bin and hex numbers. So i do not know if this kind of conversion exists also for other bases! But conversion works for other bases on the same way as for bin and hex numbers, so it must be true. * How to use the function : --------------------------- The code as been optimized in order to take the least place as possible on the Ti, as a consequence, calcul or check up (of the errors) could be a bit faster. Whenever, the answer is given instantaneously for any base and number. Maximum number of base is 36 because there is only 10 digits and 26 letters : '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ' chgbase(A,B,"String") where A and B are bounded by 2 and 36, String the number of base A which will be converted into a number of base B. String must be a character string. Result is also given as a character string. Examples : * for normal conversions : - chgbase(25,15,"Hello") -> "90B6D4" 'Hello' is a number of base 25 and '90B6D4' is a number of base 15. You can see that capital and small letters are accepted. - chgbase(32,15,"Hello") -> "1919349" 'Hello' is a number of base 32 and '1919349' of base 15. The result is not the same because 'Hello' is now of base 32! - chgbase(32,10,"000Hello") -> "1919349" As you can see, '000Hello' is the same as 'Hello'. * for signed conversions : Signed conversions starts if '+' or '-' is at the begining of the string. If not it will be normal conversions! In base 10 answers, numbers will be bounded by -(2^31-1) and 2^31-1. - chgbase(10,2,"-45") -> "+11111111111111111111111111010011" - chgbase(10,2,"+45") -> "+101101" - chgbase(10,10,"+2147483700") -> "-2147483596". '+2147483700' is larger than 2^31-1, in signed mode it is the same as '-2147483596'. - chgbase(2,10,"+11111111100001111101010101011010") -> "-7875238" * restriction : --------------- The number must be < 2^32-1 (example : in base 15, number must be < '1A20DCD80'; in base 10, they must be < '4294967295'; in base 2 < '11111111111111111111111111111111'; etc...). 2^64-1 rstriction will be reached when long long numbers will be implemented in TiGcc or TiGccLib. As a result, the character string can not have over 32 characters. Bugs and errors : ---------------- Program autodetect errors in oder the Ti no to crash, that is why the program is nearly 1200 octets long. Autodetect errors, reasons : - Usage : Numbers of Args is not equal to 3 A is not a positive num B is not a positive num String is not a character string A is not bounded by 2 and 36 B is not bounded by 2 and 36 - The base A do not fit with the number (ex : '101012' for a base 2). - Number syntax false : a character which is not a digit or a letter. - Number too large (see restriction). No known bug. No possible error during convertion! If you find any problem, contact me : Stan.Etienne@caramail.com. I can not be responsible of any damage occuring during the execution (no chance your calc crash because of this function). * History : ----------- Version : v 2.0 20/10/2000 Garbage characters bug fixed. Works now on 2.05 and all 2.0x roms. New feature : Signed mode. Height : 1389 bytes v 1.0 07/10/2000 First released. No known bug. Compiled in french and english. Compiled with TiGccLib v 2.2 Heigth : 1165 bytes * Thanks : ---------- - TiGcc team for their fabulous work. - SigmaPhi and 'AA' for testing it and give me a few advices. - me for having taken time to program it (héhé!) - You for having downloading it : I hope it will help you. * License : ----------- It is a freeware copyrighted. You are free to distribut it if you link this file unmodified. All comments are welcomed. Send it to Stan.Etienne@caramail.com.