-
Notifications
You must be signed in to change notification settings - Fork 1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[NEO3] Remove reverse() from UIntBase string representation #794
Comments
Because they are |
Do you have an example where this is commonly viewed like that? I've not seen an A quick look at C#'s bitconverter shows me this uint test_conversion = 0x1234; // 4660 decimal
Console.WriteLine(BitConverter.ToString(BitConverter.GetBytes(test_conversion))); // 34-12-00-00 Using a little bit of python to turn it back (as the used endianness is more obvious from this function) In [1]: hex(int.from_bytes(b'\x34\x12\x00\x00', byteorder='little'))
Out[1]: '0x1234' This to me tells me at least |
I think that is better to remove it because is less logic for the node, but again this will produce different addresses for neo3 and neo2 |
According to #776 neo3 already produces different addresses. So whatever the fix for that will be, we can also apply the reversing logic just there and keep NEO3 data types straight forward with less logic. |
Real question is: do we want hex prints to be big endian or little endian? @shargon no address will change, only prints are affected. Neo machine will continue to be little endian. We also need to define if scripthash is a number or not. If not number, this means we just not use UInt160 and it gets "automatically de-reversed". |
@ixje there are two policies from your example. C# bitconverter seems to print always in internal format (little endian). Python bitconverter always prints in bigendian (just like Neo) regardless of internal machine byte order running it. I guess only in struct serialization you get to see real python endianess, not sure. |
I think there should be no big endian anywhere. Everything is compiled for x86-x64 afaik, which is all little endian. What makes printing values in hex format to be correct in big endian? @igormcoelho what python bit converter are you referring to exactly? |
just closed the links haha I was reading some crazy python forums, let me try to find them. In fact, Neo is not limited to x86, right now work on projects with Neo for ARM and many other microarchitectures (on neopt project), thats why we need explicit platform endianess to be compatible (otherwise internal calculations would fail). |
@ixje just a follow-up from our last discussion. This is python in my computer (little-endian x86-64) >>> import sys
>>> sys.byteorder
'little'
>>> x=256
>>> hex(x)
'0x100' # <- this is big endian format, used on human-readable prints
>>> pack('h', x)
b'\x00\x01' # <- this is native format (little-endian), only used for internal byte array serialization. 'h' means two bytes (short type). So, although my computer is little-endian, integers (or big integers) are presented in big endian hex format, just like Neo. |
The
UInt160
andUInt256
classes always had the strange behaviour of representing their String output in reversed orderneo/neo/UIntBase.cs
Lines 120 to 123 in a8ada56
If the underlying byte array has data stored as 0xDE, 0xAD, 0xBE, 0xEF, then the string representation should also be
0xDEADBEEF
not0xEFBEADDE
.I never understood why it was there, but I hope we can remove this odd behaviour from NEO3.
The text was updated successfully, but these errors were encountered: