Dim bc As ByteConverter
Log(bc.LittleEndian)
Dim test As Int = Bit.And(Bit.ParseLong("FFFFFFFF",16), 0xFFFFFFFF)
Log(test)
Log(Bit.ToHexString(test))
Dim testBC As Int = bc.IntsFromBytes(bc.HexToBytes("FFFFFFFF"))(0)
Log(testBC)
Log(Bit.ToHexString(testBC))
With Bit, you first have to convert to a long (since you want unsigned) and then mask the long down to an integer. With ByteConverter, create an array of bytes from the hex string and then convert those bytes to an integer array, selecting the first array element (element 0) as your output. You may want to validate your input or wrap either method in a try/catch, just in case if invalid input.
Even though both numbers print out as -1, it does not matter. The bit representation is the same as the unsigned number you are looking for.
Dim bc As ByteConverter
Dim DATA as String = "f1eea25a"
Log(bc.LittleEndian)
' Dim test As Int = Bit.And(Bit.ParseLong("FFFFFFFF",16), 0xFFFFFFFF)
' Log(test)
' Log(Bit.ToHexString(test))
Dim testBC As Int = bc.IntsFromBytes(bc.HexToBytes(DATA))(0)
Log(testBC)
Log(Bit.ToHexString(testBC))
In computer science, an integer is a data type that represents mathematical integers. They may be of different sizes and may or may not be allowed to contain negative values. In a computer they are commonly represented as a group of binary digits.
cryptii.com
if you input "f1eea25a"
select 32 bit unsigned interger and select big endian
the output is 4058948186
Both numbers have the same bit format. Java just happens to display that bit format as an unsigned signed int. Unless you do computations with that number, you're good to go
Dim converter As ByteConverter
Dim a(8) As Byte
Dim i() As Byte = converter.HexToBytes(reduced_string)
Bit.ArrayCopy(i, 0, a, 4, 4)
Dim ll() As Long = converter.LongsFromBytes(a)
Log(ll(0))
For display purposes, you'll have to convert the 32 bits into a long in order to display properly. But technically, the 32 bits represent the same 32 bits as an "unsigned" integer. In the end, the bits are the same, but how the system treats them is determined by signed / unsigned status.
B4X:
Dim test As Int = Bit.And(Bit.ParseLong("FFFFFFFF",16), 0xFFFFFFFF)
Log(test)
Log(UnsignedIntToLong(test))
Sub UnsignedIntToLong(input As Int) As Long
Return Bit.ParseLong(Bit.ToHexString(input), 16)
End Sub
It all depends on what you are trying to accomplish. If you are trying to create a 32 bit representation of an unsigned integer that you later need to transfer to another system, store away, do some Bit operations on, then I've shown you one way of doing it. If all you are trying to do is display the content of a 32 bit representation of an unsigned integer, then I would go with @emexes solution above.
Dim NegativeInt As Int = -123
Log(Bit.AndLong(NegativeInt, 0x0FFFFFFFF)) 'magic extra zero to make hex literal Long (positive) rather than Int (negative)