This is a function I wrote a while back. There are many ways to convert decimal to binary, and several have already been posted, but I really like this algorithm that I wrote. I was trying to go for a KISS approach here, but feel free to make it more professional.
VB Code:
Public Function ChangeBase(N As Long, NewBase As Integer) As String Dim K As Long Dim L As Long Do K = N \ NewBase L = N - (K * NewBase) N = K ChangeBase = L & ChangeBase DoEvents Loop Until K < NewBase ChangeBase = K & ChangeBase End Function
This will convert a decimal value to base 2, 3, 4, 5... whatever. However, if you want to convert to a base above base 10, you'll have to write some sort of code to catch values above 10 and convert them to a letter in the alphabet.




Reply With Quote