you said:
LittleEndian takes a 32-bit integer and outputs 4 bytes in little-endian order.
In case of Bitcoin block header SwapOrder operates on a string of hex numbers, reversing their order
2 bytes-wise ( hex pairs)
example below
The problem is with decimal number converted to little Endian
since
decimal value is converted to Hexadecimal value
1222 4C6
Epoch Unix time (decimal)
1305998791 4DD7F5C7 (even number of hex symbols
Now I need to convert hexadecimal value to a string of hex digits ( 0,1,2.... A,C...F) - hex (base 16) representation
and append "0" to "4C6" to get even number of hex digits and operate SwapOrder 2 bytes - wise
$time = littleEndian(1305998791);
from
https://en.bitcoin.it/wiki/Block_hashing_algorithm
(1305998791)10 = (4DD7F5C7)16
So in theory and practice, I am safe converting today Unix epoch time (decimal number) to hexadecimal value with even number of hex digits - hex (base 16) representation
Hex2String conversion is not the right tool, converting
4DD7F5C7
to
M×õÇ (ASCII string)
so the following code looks to work fine converting Unix epoch time value = 1305998791 to hex (base 16) string followed by SwapOrder(num.toString(16))
Click the button to display the formatted number.
if I am wrong, please correct me