vb.net二进制转进制 vbs 二进制文件读写

vb.net 中2、8、10、16进制转换代码怎么写

Option Explicit

成都创新互联公司主营镜湖网站建设的网络公司,主营网站建设方案,重庆APP软件开发,镜湖h5成都微信小程序搭建,镜湖网站营销推广欢迎镜湖等地区企业咨询

Dim Jz As Integer, K As Boolean

Private Sub Command1_Click()

Pic.Cls

If K Then Jz = Val(Qtjz.Text)

If Pd(Text1.Text, Jz) Then Pic.Print "选择的进制与数不符": Exit Sub

If Jz = 0 Then Pic.Print "请先输入进制" Else Pic.Print Zh(Text1.Text, Jz)

End Sub

Private Sub Command2_Click()

End

End Sub

Private Sub Frame1_DragDrop(Source As Control, X As Single, Y As Single)

End Sub

Private Sub Option1_Click(Index As Integer)

K = False

Select Case Index

Case 0

Jz = 2

Case 1

Jz = 8

Case 2

Jz = 10

Case 3

Jz = 16

Case 4

K = True

Qtjz.Text = ""

Qtjz.SetFocus

End Select

If Index 4 Then Command1.SetFocus

End Sub

Private Sub Qtjz_Click()

Qtjz.Text = ""

End Sub

Private Sub Text1_Click()

Text1.Text = ""

End Sub

Private Function Zh(a As String, b As Integer) As Integer

Dim c As String, i, d As Integer

a = LCase(a)

For i = 1 To Len(a)

c = Mid(a, Len(a) + 1 - i, 1)

If Asc(c) 96 Then d = Asc(c) - 87 Else d = Val(c)

Zh = Zh + d * b ^ (i - 1)

Next i

End Function

Private Function Pd(a As String, b As Integer) As Boolean

Dim c As String, i, d As Integer

Pd = False

For i = 1 To Len(a)

c = Mid(a, Len(a) + 1 - i, 1)

If Asc(c) 96 Then d = Asc(c) - 87 Else d = Val(c)

If d b - 1 Then Pd = True: Exit Function

Next i

End Function

vb.net 二进制读取文件

VB.NET打开二进制文件用fileopen完成,打开二进制文件的形式为:openmode.binary

读取二进制文件用的是fileget方法,写入二进制文件用的是fileput方法。

应用示例:将一批随机数保存在一个dat文件中,然后再将其提取到文本框中。

二进制文件的读写一批随机数的存取,程序为:

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

Dim x, i, fn As Integer

Dim s As String = ""

fn = FreeFile()

FileOpen(fn, "d:\data.dat", OpenMode.Binary)

For i = 1 To 8

x = Int(Rnd() * 100)

s = s + Str(x)

FilePut(fn, x)

Next

FileClose(fn)

TextBox1.Text = s

End Sub

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click

Dim x, fn As Integer

Dim s As String = ""

fn = FreeFile()

FileOpen(fn, "d:\data.dat", OpenMode.Binary)

Do While Not EOF(fn)

FileGet(fn, x)

s = s + Str(x) + " "

Loop

FileClose(fn)

TextBox1.Text = s

End Sub

用VB.NET将二进制数转换为十进制数

.NET 程序写成你这样也算厉害了,好好看看下面的代码

Sub Main()

Console.WriteLine("请输入一个二进制数")

Console.WriteLine(bin2int(Console.ReadLine()))

Console.ReadKey()

End Sub

Function bin2int(ByVal bin As String) As Integer

Dim i As Long

For i = 1 To bin.Length

bin2int = bin2int * 2 + Val(Mid(bin, i, 1))

Next i

End Function

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二进制转进制 vbs 二进制文件读写
文章位置:http://scyanting.com/article/dohodjp.html