Convert int to byte array online
I couldn’t find it, so I created it
For those who just want to use it, the converter is here. Full code on GitHub. For an explanation of the code, read on.
I work a lot with BLE, and BLE characteristics are byte arrays. For example, I want to convert the current Unix timestamp to a byte array, send it to a device, and then check the memory of the device, parse the timestamp and see if it’s the correct time.
I guess the year isn’t 3534, huh?
So let’s get debugging.
First, let’s make sure we are getting the correct timestamp (got 1701264027246
) and check the timestamp here — looks good.
Then check the function that turns it into bytes, I got the following:
[0, 0, 1, 140, 27, 60, 238, 110]
I would like to check that it is actually the same int. I searched online back and forth. There are tons of binary-hex converters, decimal-hex, decimal-binary, what have you. But I couldn’t find a converter where I can put the bytes, in decimal or hex format (sometimes the logs are in hex) and get an int.
So I created it, using HTML & JavaScript, and uploaded it on my site.