16 bit unsigned short byte flip in VB.NET

后端 未结 2 420
时光取名叫无心
时光取名叫无心 2021-01-29 11:44

What would be an example of byte flipping in VB.NET?

16 bit unsigned short

Before the flip:

02 00 0D 78 10 20 40 80 F1 F2 F4 F8          


        
2条回答
  •  挽巷
    挽巷 (楼主)
    2021-01-29 12:11

    You could write as you go, something like:

    Dim file = dialog.FileName
    
    Using output = New BinaryWriter(New FileStream( _
                                      file, _
                                      FileMode.Append, _
                                      FileAccess.Write, _
                                      FileShare.Read))
    
        Using input = New BinaryReader(New FileStream( _
                                         file, _
                                         FileMode.Open, _
                                         FileAccess.Read, _
                                         FileShare.ReadWrite))
            Dim bufferLength = 2
            While bufferLength = 2
                Dim buffer = input.ReadBytes(2)
                bufferLength = buffer.Length
                If bufferLength = 2 Then
                    output.Write(buffer(1))
                    output.Write(buffer(0))
                Else If bufferLength = 1 Then
                    output.Write(buffer(0))
                End If
            End While
        End Using
    End Using
    

提交回复
热议问题