vb程式設計,用do-while迴圈實現十進位制轉二進位制和十六進位制:1、十進位制轉為二進位制:Sub DecimalToBinary()Dim intNumber As IntegerDim intRemainder As IntegerDim strRemainder As StringDim strBinaryNumber As StringintNumber = CInt(InputBox("Enter number in decimal:", "DECIMAL TO BINARY CONVERSION"))Do While intNumber >= 1 intRemainder = intNumber Mod 2 strRemainder = CStr(intRemainder) intNumber = intNumber \ 2 strBinaryNumber = strRemainder & strBinaryNumberLoopMsgBox "The Number in Binary is : " & strBinaryNumber, , "DECIMAL TO BINARY CONVERSION"End Sub2、十進位制轉十六進位制:Sub DecimalToHexadecimal() Dim intNumber As Integer Dim intRemainder As Integer Dim strRemainder As String Dim strHexaNumber As String intNumber = CInt(InputBox("Enter number in decimal:", "DECIMAL TO HEXADECIMAL CONVERSION")) Do While intNumber >= 1 intRemainder = intNumber Mod 16 strRemainder = CStr(intRemainder) intNumber = intNumber \ 16 Select Case strRemainder Case "10": strRemainder = "A" Case "11": strRemainder = "B" Case "12": strRemainder = "C" Case "13": strRemainder = "D" Case "14": strRemainder = "E" Case "15": strRemainder = "F" End Select strHexaNumber = strRemainder & strHexaNumber Loop MsgBox "The Number in Hexadecimal is : " & strHexaNumber, , "DECIMAL TO HEXADECIMAL CONVERSION"End Sub
vb程式設計,用do-while迴圈實現十進位制轉二進位制和十六進位制:1、十進位制轉為二進位制:Sub DecimalToBinary()Dim intNumber As IntegerDim intRemainder As IntegerDim strRemainder As StringDim strBinaryNumber As StringintNumber = CInt(InputBox("Enter number in decimal:", "DECIMAL TO BINARY CONVERSION"))Do While intNumber >= 1 intRemainder = intNumber Mod 2 strRemainder = CStr(intRemainder) intNumber = intNumber \ 2 strBinaryNumber = strRemainder & strBinaryNumberLoopMsgBox "The Number in Binary is : " & strBinaryNumber, , "DECIMAL TO BINARY CONVERSION"End Sub2、十進位制轉十六進位制:Sub DecimalToHexadecimal() Dim intNumber As Integer Dim intRemainder As Integer Dim strRemainder As String Dim strHexaNumber As String intNumber = CInt(InputBox("Enter number in decimal:", "DECIMAL TO HEXADECIMAL CONVERSION")) Do While intNumber >= 1 intRemainder = intNumber Mod 16 strRemainder = CStr(intRemainder) intNumber = intNumber \ 16 Select Case strRemainder Case "10": strRemainder = "A" Case "11": strRemainder = "B" Case "12": strRemainder = "C" Case "13": strRemainder = "D" Case "14": strRemainder = "E" Case "15": strRemainder = "F" End Select strHexaNumber = strRemainder & strHexaNumber Loop MsgBox "The Number in Hexadecimal is : " & strHexaNumber, , "DECIMAL TO HEXADECIMAL CONVERSION"End Sub