BarbaraS
New member
- Joined
- Jun 21, 2025
- Messages
- 2
- Programming Experience
- 1-3
Hello.
I wrote the number 10166 to a binary file. I swapped the bytes beforehand. This results in the number
I can read back the value the function returned, but I can't get the number 10166 back after swapping the bytes. Here's the code.
Private Function _swap4(valueAs Integer) As Integer
Dim tmp As Integer
tmp = value And &HFF
tmp = ((value And &HFF00) >> &H8) Or (tmp << &H8)
tmp = ((value And &HFF0000) >> &H10) Or (tmp << &H8)
tmp = ((value And &HFF000000) >> &H18) Or (tmp << &H8)
_swap4 = tmp
End Function
Private Sub Main()
Dim num as Integer = 10166
num = _swap4(num)
End Sub
This results in num = -1238958080 (the hex value in the file is then 00 00 27 B6).
When I read the value back in, I don't get the 10166 back after calling _swap4, but instead -74.
Where am I making a mistake?
I have to convert the read value again using _swap4, right?
I wrote the number 10166 to a binary file. I swapped the bytes beforehand. This results in the number
I can read back the value the function returned, but I can't get the number 10166 back after swapping the bytes. Here's the code.
Private Function _swap4(valueAs Integer) As Integer
Dim tmp As Integer
tmp = value And &HFF
tmp = ((value And &HFF00) >> &H8) Or (tmp << &H8)
tmp = ((value And &HFF0000) >> &H10) Or (tmp << &H8)
tmp = ((value And &HFF000000) >> &H18) Or (tmp << &H8)
_swap4 = tmp
End Function
Private Sub Main()
Dim num as Integer = 10166
num = _swap4(num)
End Sub
This results in num = -1238958080 (the hex value in the file is then 00 00 27 B6).
When I read the value back in, I don't get the 10166 back after calling _swap4, but instead -74.
Where am I making a mistake?
I have to convert the read value again using _swap4, right?