By your logic, all the numbers under "10" in the decimal system by themselves aren't "true numbers".
It's not "2 + 2 = 4", it's "02 + 02 = 04".
It's not "5 + 5 = 10", it's "05 + 05 = 10".
Seems silly, doesn't it?
The thing to keep in mind is that a hexadecimal number is just that: a number. Leading zeroes are meaningless in numbers, and are generally only included for spacing/sorting purposes.
dechex$ works perfectly, and it properly converts any
decimal number you give it to the proper corresponding hexadecimal representation.
The problem is you're assigning meaning to the output that isn't there. You're trying to get representations of
bytes from dechex$(), NOT representations of
numbers. There is an important distinction there; dechex$() ONLY works with numbers, and ONLY returns numbers. If you want those numbers to mean something else, you have to do the conversion yourself.
After all, what number of leading zeroes is "proper"? One zero, to make sure all numbers returned are two-digit byte representations?
Well, what if I don't want bytes? What if I want 32-bit words? "dechex$() doesn't work properly, 254 should be "000000FE", not "FE", it's broken."
Heck, it gets worse than that.
"000000FE" is a 32-bit word,
in big-endian order. (See
en.wikipedia.org/wiki/Endianness for an overview of what this means.) What if I want it displayed in little-endian order, like x86(and Windows) use internally? Then it's "dechex$ is wrong, it returns "000000FE" for 254 instead of "FE000000". It doesn't format the numbers properly."
It's not supposed to. It's assigning meaning to numbers that isn't there.
You're breaking the bytes of a string up into individual values, converting the numbers into a different format, and then reassembling those values. It's up to you to make sure the meaning stays consistent when doing that, because dechex$() only works with numbers.
Now, if LB had some sort of built-in function like a lot of languages do, that explicitly converts the bytes of a string to their corresponding hex values(along the lines of "StringToHex$()" or "str.ToHex()" or something), then yes, getting the values that you were getting would be incorrect, and that would be a bug in LB. But that's
not what dechex$() is. It's in the name: DecHex. DECimal to HEXadecimal. Convert one
number from base 10 representation to base 16 representation.