vb 十进制转换成 八进制 二进制原码 二进制补码 二进制反码 程序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" 进制后:"vbTab)
If (arr(1) = 1) Then
Console.Write("-")
End If
For i = len1 To 2 Step -1
Console.Write(arr(i))
Next
【vb.net二进制反码 二进制转十进制的代码怎么写】Console.WriteLine()
arr = TransToSourceCode(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 = 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)进制数,结果存在arr数组中
'arr(0)存储长度, arr(1)存储符号位:1为负,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
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) = carr(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 将文件转化成二进制首先引入System.IO命名空间
Imports System.IO
然后使用文件流来读入数组:
Dim bytes() As Byte
Using fs As New FileStream(文件路径,FileMode.Open)
ReDim bytes(fs.Length-1)
fs.Read(bytes,0,fs.Length)
fs.Close()
End Using
这样bytes就是整个文件的所有字节了
从字节生成Image:
Dim img As Image = Image.FromStream(New MemoryStream(bytes))
img就是图片了
vb.net如何将图片转二进制'容易,用api,查一查SetBitmapBits
'新建工程,增加一个 command button ,一个 picture box , 将图片加载到 picture box.
'将代码粘贴到 Form1
Private Type BITMAP
bmType As Long
bmWidth As Long
bmHeight As Long
bmWidthBytes As Long
bmPlanes As Integer
bmBitsPixel As Integer
bmBits As Long
End Type
Private Declare Function GetObject Lib "gdi32" Alias "GetObjectA" (ByVal hObject As Long, ByVal nCount As Long, lpObject As Any) As Long
Private Declare Function GetBitmapBits Lib "gdi32" (ByVal hBitmap As Long, ByVal dwCount As Long, lpBits As Any) As Long
Private Declare Function SetBitmapBits Lib "gdi32" (ByVal hBitmap As Long, ByVal dwCount As Long, lpBits As Any) As Long
Dim PicBits() As Byte, PicInfo As BITMAP, Cnt As Long
Private Sub Command1_Click()
'Get information (such as height and width) about the picturebox
GetObject Picture1.Image, Len(PicInfo), PicInfo
'reallocate storage space
ReDim PicBits(1 To PicInfo.bmWidth * PicInfo.bmHeight * 3) As Byte
'Copy the bitmapbits to the array
GetBitmapBits Picture1.Image, UBound(PicBits), PicBits(1)
'Invert the bits
For Cnt = 1 To UBound(PicBits)
PicBits(Cnt) = 255 - PicBits(Cnt)
Next Cnt
'Set the bits back to the picture
SetBitmapBits Picture1.Image, UBound(PicBits), PicBits(1)
'refresh
Picture1.Refresh
End Sub
vb.net二进制反码的介绍就聊到这里吧 , 感谢你花时间阅读本站内容,更多关于二进制转十进制的代码怎么写、vb.net二进制反码的信息别忘了在本站进行查找喔 。
推荐阅读
- 关注公众号小程序的积分,微信公众号里第三方软件实现积分功能
- 益智小游戏管家逃生怎么玩,老管家逃生游戏
- html鼠标浮动特效代码大全,html 鼠标悬浮
- mysql怎么输入 mysql怎么输入中文
- 新媒体如何管控客户,新媒体应该如何管理
- cpu是什么起什么作用,cpu是什么起什么作用是什么
- redis怎么关闭端口,redistemplate关闭连接
- java烟花源代码下载 python炫酷烟花源代码
- html5全栈开发学什么,h5全栈开发就业前景