vb.net补零 vb中loop缺少do

vb怎么判断变量里的字符个数不够两个自动在前面补0vb判断变量里vb.net补零的字符个数不够两个自动在前面补0vb.net补零,提供两种常用的方法;
1、根据长度判断;
a = 5 '注意这里a如果定义为数字类型(Integer、long等)vb.net补零 , 补零后的变量尽量换一个其vb.net补零他变量值vb.net补零,比如b
If Len(a)2 Then b = "0"aelse b=a ‘如果a长度小于2,就前面补零
2、先补零,再取后2位
a=5
b = "0"a
b= Right(b, 2)
vb 十进制转换成 八进制 二进制原码 二进制补码 二进制反码 程序VB.NET控制台程序vb.net补零:
Module module3
Sub Main()
Dim i As Integer
Dim num As Integer = -35
Dim R As Integer = 8
Dim arr(33) As Integer
Dim len As Integer
arr = TransToR(num, R)
len = arr(0)
Console.Write(num" 转换成 "R" 进制后vb.net补零:"vbTab)
If (arr(1) = 1) Then
Console.Write("-")
End If
For i = len + 1 To 2 Step -1
Console.Write(arr(i))
Next
Console.WriteLine()
arr = TransToSourceCode(num)
Console.Write(num" 转换成32位二进制源码后vb.net补零:"vbTab)
Console.Write(arr(1))
For i = 32 To 2 Step -1
Console.Write(arr(i))
Next
Console.WriteLine()
arr = TransToReverseCode(num)
Console.Write(num" 转换成32位二进制反码后:"vbTab)
Console.Write(arr(1))
For i = 32 To 2 Step -1
Console.Write(arr(i))
Next
Console.WriteLine()
arr = TransToCompensatoryCode(num)
Console.Write(num" 转换成32位二进制补码后:"vbTab)
Console.Write(arr(1))
For i = 32 To 2 Step -1
Console.Write(arr(i))
Next
Console.WriteLine()
End Sub
'将十进制数num转换为R(2=R=9)进制数vb.net补零,结果存在arr数组中
'arr(0)存储长度, arr(1)存储符号位:1为负vb.net补零 , 0为正
Function TransToR(ByVal num As Integer, ByVal R As Integer) As Integer()
Dim arr(33) As Integer
arr(0) = 0'初始长度
'设置符号位
If (num0) Then
arr(1) = 1
【vb.net补零 vb中loop缺少do】Else
arr(1) = 0
End If
num = Math.Abs(num)
While num0
arr(0) = arr(0) + 1
arr(arr(0) + 1) = num Mod R
num \= R
End While
Return arr
End Function
'将十进制数num转换为二进制原码
Function TransToSourceCode(ByVal num As Integer) As Integer()
Dim arr(33) As Integer
Dim i As Integer
arr = TransToR(num, 2)
'高位补零
For i = arr(0) + 2 To 32
arr(i) = 0
Next
arr(0) = 32
Return arr
End Function
'将十进制数num转换为二进制反码
Function TransToReverseCode(ByVal num As Integer) As Integer()
Dim arr(33) As Integer
Dim i As Integer
arr = TransToSourceCode(num)
If num = 0 Then
Return arr
End If
'除符号位外各位取反
For i = 2 To 33
arr(i) = 1 - arr(i)
Next
Return arr
End Function
'将十进制数num转换为二进制补码
Function TransToCompensatoryCode(ByVal num As Integer) As Integer()
Dim arr(33) As Integer
Dim i As Integer
Dim c As Integer = 0'进位
arr = TransToReverseCode(num)
If num = 0 Then
Return arr
End If
'末尾加1
i = 2
arr(i) += 1
Do While True
arr(i) = c + arr(i)
c = arr(i) \ 2
arr(i) = arr(i) Mod 2
i += 1
If c1 Then
Exit Do
End If
Loop
Return arr
End Function
End Module
VB.NET中如何使string的011 +1 = string的012Dim a As String = "011"
Dim b As String = "1"
Dim c As String
c = (CInt(a) + CInt(b)).ToString.PadLeft(3, "0")

推荐阅读