liveBook · Manning

Bytes

As explained in Rust in Action: Systems programming concepts and techniques

A byte is a unit of digital information consisting of eight binary bits.

A byte is eight binary bits. It can be viewed as two four-bit nibbles, making it useful for splitting instruction data and storing raw values. section 5.7.1

Bytes appear in two practical forms:

  • Instruction data: a CHIP-8 opcode contains a high byte and a low byte; each byte can be divided into high and low nibbles for decoding. section 5.7.1
  • Stored data: a key-value store represents keys and values as sequences of bytes, using [u8] for arbitrary-length data. section 7.5.1
  • Text data: Rust distinguishes a single byte literal such as b'a' from a one-byte byte slice such as b"a". section 10.6

Extracting bytes and nibbles from an opcode

Given opcode 0x71E4, masking and shifting extract c = 0x7, x = 0x1, y = 0xE, and d = 0x4. Wider fields can also be read as nnn = 0x1E4 or kk = 0xE4. section 5.7.1

Listing 5.18 Definition of the CPU used in listing 5.22
struct CPU {
 
    current_operation: u16,    #1
    registers: [u8; 2],        #2
 
}

A compact CPU definition shows bytes in Rust through u8 register storage alongside a larger u16 current operation. section 5.7.1

How Rust in Action: Systems programming concepts and techniques covers it

How deep it goes
Explains byte composition through nibbles and demonstrates masking, shifting, and [u8] storage without broader binary representation details.
Examples
Uses CHIP-8 opcode fields, u8 registers, country-capital records, and Rust byte literals.
What it assumes
Assumes bitwise shifts and AND for opcode decoding, while introducing byte sequences through Rust's [u8] representation.
What you can do after
Apply it via Rust to decode opcode fields and represent arbitrary-length stored data as byte sequences.
How it connects
Connects bytes with bits, nibbles, bitwise operations, opcodes, CPU registers, memory, and key-value stores.

Also explained in

Compare how 7 books explain bytes →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Rust in Action: Systems programming concepts and techniques. The section links point to the parts of the book it draws on.