Converting Numbers Between Bases
While the quotient is not zero… Divide the decimal number by the new base. Make the remainder the next digit to the left in the answer. Replace the original dividend with the quotient. Converting Decimal to Other Bases
Converting Decimal to Binary Dim quotient, bDigit As Integer Dim bString As String quotient = ‘number to be converted bDigit = 0 bString = VbNullString
Do While quotient not = 0 bDigit = quotient Mod 2 bString = CStr(bDigit) & bString quotient = quotient \ 2 Loop Converting Decimal to Binary
Converting Binary to Decimal Multiply the bit in each position by the power of 2 in that position, and Sum the products.
Converting Binary to Decimal Dim bLen, number, c As Integer Dim bString As String bString = ‘the binary string to convert bLen = bString.Length-1
Converting Binary to Decimal For c = 0 To bLen number = number + _ Val(bString(c)) * 2 ^ (bLen – c) Next