I was asked to convert the integers to 32-bit binary numbers.
So is used integer.toString(2) and got the required value in 32-bit binary format of 0'sand 1's. But actually what I was asked to do is convert the integer into 4 bytes of data.
I am unable to get the output as suggested. I have used integer.toString(8), integer.toString(16). but of no use.
Example:
num=1065489844
num.toString(2) //Output: 111111100000100001010110110100
num.toString(8) //Output: 7740412664
Please let me know, where I am lacking.
toString()only supports bases up to 36.x. Then usingx | 0will ensure that it's a 32-bit integer. I've no idea what you mean by "binary number". Every integer in every programming language is stored as bits.