Math Algorithms

The following is a collection of algorithms or proven methods for solving common problems. Before you incorporate any of these into your programs, it is recommended that you fully understand the code, and that you test the algorithm with the range of numbers that you intend using.

You will notice that for the most part, with few indicated exceptions, there are no type declarations on the variables used, and therefore, as a default, integer variables are assumed, and the logic has been tested using integers.

Also, with few indicated exceptions, the variables are assumed to be positive numbers.

It is important to note that many of the following algorithms were chosen as the best available under intensive scrutiny and testing by members of the Qbasicnews and QBNZ forums.


BinarySearch - How to search sorted arrays in binary time. (ie: very fast)
FibonacciSeries - A recursive and iterative approach to the Fibonacci Series.
PowerofTwo - Determine if a number is a power of 2.
GenerateGrayCode - Generate a gray code pattern.
NextMultiple - Compute the next multiple.
NearestMultiple - Compute the nearest multiple.
RoundingNumbers - Rounding numbers..
DecimalToBinary - Convert a decimal base number to binary base.
AddOrNotBinary - Binary to decimal conversion, sort of.
ChangeBase(?) - Change a number's representation from one base to another.
CentigradeToFahrenheit - Centigrade to Fahrenheit conversion.
GenerateRandomNumber - Generate a random number in a certain range.
GreatestCommonDivisor - Euclid's algorithm for generating the greatest common divisor of two numbers.

EasterDate - Get the date of occurence of the Easter holiday by entering the year. Four variations.

MathAlgorithms - page last edited 2006-10-31 22:18:51 by (home) (edit)
Blast WIKI - by RoboticBoy - edited and tweaked for our evil purposes by Hexadecimal Disaster