Click here to Skip to main content
15,897,273 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Am I right in thinking that in a little endian 4 byte signed int, the sign is held in the top bit of the 4th byte? i.e.(in binary) xxxxxxxx xxxxxxxx xxxxxxxx 1xxxxxxx is negative and xxxxxxxx xxxxxxxx xxxxxxxx 0xxxxxxx is positive?

What I have tried:

Since I only *suspect* that the data I am looking at is signed, rather than *knowing* I am uncertain as to how to prove things either way.
Posted
Updated 16-Jan-19 7:53am

1 solution

OH, if you are wanting to determine how endian-ness works in VB you could try something like:
(Use your values and try it out.)
VB
Dim a() As Byte = { &H1C }
Dim b(3) As Byte
If BitConverter.IsLittleEndian Then
    b(0) = a(0)
Else
    b(3) = a(0)
End If
Dim key As Integer = BitConverter.ToInt32(b, 0)

Found at: Change byte array to integer in VB.net - Stack Overflow[^]


How about this?
VB
Private Function BArrayToInt(ByRef bArray() As Byte) As Integer
    Dim iReturn As Integer
    Dim i As Integer
    For i = 0 To UBound(bArray) - LBound(bArray)
        iReturn = iReturn + bArray(i) * 2 ^ i
    Next i

    BArrayToInt = iReturn

End Function


from : bytearray - Byte Array to a Signed Integer in VB6 - Stack Overflow[^]
 
Share this answer
 
v2
Comments
Member 14100511 17-Jan-19 0:58am    
Thanks raddevus. I should have said I'm working in VB6 as befits my age.
I don't see how the VB6 solution is going to return a signed value, but will give it a try.

Mostly my question is about where the sign bit is held in a little endian 4 byte number.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900