Lack of a proper padding in a binary conversion


I try to convert hex to binary using this code:

var pattern='5c48a02b8c00';
var pattern_bits ="";
msg.payload=parseInt("0x"+pattern).toString(2).padStart(4, '0');
return msg;

It returns the string:10111000100100010100000001010111000110000000000. I have checked this result in online calc, and the result is:010111000100100010100000001010111000110000000000* The difference is in the first zero from the left. Probably it is because 5 is 101. But based on code 101 should be padded to four characters (0101). What is wrong?

You need padStart(48, '0').
You want 48 bits total.
Numerically there is no difference of course.

What is it that you want to do with the result?

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.