I'm creating a tutorial on JavaScript, and as I deal with explaining bitwise operators, etc. How negative numbers are represented in JavaScript keep coming up.
I believe all I need to describe in my tutorial is two's complement, but do I also need to describe one's complement, or is one's complement irrelevant in JavaScript?
How about floating point numbers, positive and negative numbers, in JavaScript?
x = 4is a float. However, bitwise operators forcefully convert a number to 32-bit integer, so3.14 | 0will produce3but also(2 ** 31 - 1) | 0is2147483647yet(2 ** 31) | 0is-2147483648.Array.from(new Uint8ClampedArray(new Float64Array([ 420.69 ]).buffer), (byte) => byte.toString(2).padStart(8, "0")).join(""). ReplaceFloat64ArraybyInt32Arrayto inspect integers. The bytes may, however, be reversed, based on endianness.