Presentation is loading. Please wait.

Presentation is loading. Please wait.

Converting Numbers Between Bases

Similar presentations


Presentation on theme: "Converting Numbers Between Bases"— Presentation transcript:

1 Converting Numbers Between Bases

2 Converting Decimal to Other 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.

3 Converting Decimal to Binary
Dim quotient, bDigit As Integer Dim bString As String quotient = ‘number to be converted bDigit = 0 bString = VbNullString

4 Converting Decimal to Binary
Do While quotient not = 0 bDigit = quotient Mod 2 bString = CStr(bDigit) & bString quotient = quotient \ 2 Loop

5 Converting Binary to Decimal
Multiply the bit in each position by the power of 2 in that position, and Sum the products.

6 Converting Binary to Decimal
Dim bLen, number, c As Integer Dim bString As String bString = ‘the string to convert bLen = bString.Length-1

7 Converting Binary to Decimal
For c = 0 To bLen number += Conversion.Val(bString(c))_ * 2 ^ (bLen – c) Next


Download ppt "Converting Numbers Between Bases"

Similar presentations


Ads by Google