liveBook · Manning

Regular binary layout

As explained in JavaScript in Depth

An unsigned binary encoding in which each bit position contributes a power of two to a nonnegative integer.

Why can the same eight bits represent 255 or −1? Their meaning depends on the layout. In regular binary layout, every bit contributes to a nonnegative integer; there is no sign bit. The rightmost position contributes 2⁰, the next 2¹, and so on. section 3.1.1

Binary: 1011 = 1×2³ + 0×2² + 1×2¹ + 1×2⁰ = 11 in decimal

The set bits in 1011 contribute 2³, 2¹, and 2⁰, giving 11. section 3.1.1

Eight bits have 2⁸ possible patterns, so one byte in this layout represents 0 through 255. For example, 00000000 is 0 and 00000100 is 4. In the contrasting eight-bit two’s-complement layout, 11111111 represents −1 rather than 255. Check the encoding before interpreting a bit pattern as a number. section 3.1.1

How JavaScript in Depth covers it

How deep it goes
Works through positional values and the eight-bit range, then contrasts two’s complement without detailing unsigned arithmetic.
Examples
Uses short bit patterns, including 00000000, 00000100, and 1011, to show numeric values.
What it assumes
Builds from bit positions and powers of two rather than assuming familiarity with binary encoding.
What you can do after
Evaluate/understand an unsigned byte’s value and distinguish its interpretation from a signed layout.
How it connects
Connects bits, bytes, powers of two, sign bits, and two’s complement.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of JavaScript in Depth. The section links point to the parts of the book it draws on.