vb.net二進(jìn)制轉(zhuǎn)進(jìn)制 vbs 二進(jìn)制文件讀寫(xiě)

vb.net 中2、8、10、16進(jìn)制轉(zhuǎn)換代碼怎么寫(xiě)

Option Explicit

成都創(chuàng)新互聯(lián)公司主營(yíng)鏡湖網(wǎng)站建設(shè)的網(wǎng)絡(luò)公司,主營(yíng)網(wǎng)站建設(shè)方案,重慶APP軟件開(kāi)發(fā),鏡湖h5成都微信小程序搭建,鏡湖網(wǎng)站營(yíng)銷(xiāo)推廣歡迎鏡湖等地區(qū)企業(yè)咨詢(xún)

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 "選擇的進(jìn)制與數(shù)不符": Exit Sub

If Jz = 0 Then Pic.Print "請(qǐng)先輸入進(jìn)制" 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 二進(jìn)制讀取文件

VB.NET打開(kāi)二進(jìn)制文件用fileopen完成,打開(kāi)二進(jìn)制文件的形式為:openmode.binary

讀取二進(jìn)制文件用的是fileget方法,寫(xiě)入二進(jìn)制文件用的是fileput方法。

應(yīng)用示例:將一批隨機(jī)數(shù)保存在一個(gè)dat文件中,然后再將其提取到文本框中。

二進(jìn)制文件的讀寫(xiě)一批隨機(jī)數(shù)的存取,程序?yàn)椋?/p>

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將二進(jìn)制數(shù)轉(zhuǎn)換為十進(jìn)制數(shù)

.NET 程序?qū)懗赡氵@樣也算厲害了,好好看看下面的代碼

Sub Main()

Console.WriteLine("請(qǐng)輸入一個(gè)二進(jìn)制數(shù)")

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 將文件轉(zhuǎn)化成二進(jìn)制

首先引入System.IO命名空間

Imports System.IO

然后使用文件流來(lái)讀入數(shù)組:

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就是整個(gè)文件的所有字節(jié)了

從字節(jié)生成Image:

Dim img As Image = Image.FromStream(New MemoryStream(bytes))

img就是圖片了

分享名稱(chēng):vb.net二進(jìn)制轉(zhuǎn)進(jìn)制 vbs 二進(jìn)制文件讀寫(xiě)
分享地址:http://muchs.cn/article28/dohodjp.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供外貿(mào)建站、全網(wǎng)營(yíng)銷(xiāo)推廣、ChatGPT、響應(yīng)式網(wǎng)站、軟件開(kāi)發(fā)、品牌網(wǎng)站制作

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶(hù)投稿、用戶(hù)轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來(lái)源: 創(chuàng)新互聯(lián)

營(yíng)銷(xiāo)型網(wǎng)站建設(shè)