1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
#include <assert.h>
#include <stdint.h>
typedef unsigned char uint8_t;

int main(int argc, char* argv[]) {
    uint buf[8];
    int pos_bytes = 0;
    int pos_bit   = 0;  // 0 is most-significant (128's place), 7 is least significant (1's place)
    
    // Step 1:  Write 011 to an empty buffer.
    //   ∙ 1a:  Write 0 to an empty buffer.  (nothing to do)
    //   ∙ 1b:  Write 1 to position 1 (2nd bit)
    //          Byte 0 starts as 00000000₂ and want to get 01000000₂.
    buf[0] = 1 << 6;  // can use = because the byte is empty
    //   ∙ 1c:  Write 1 to position 2 (3nd bit)
    //          Byte 0 starts as 00000000₂ and want to get 01000000₂.
    buf[0] |= 1 << 5;  // can use = because the byte is empty
    
    return EXIT_SUCCESS;
}
/* vim: set tabstop=4 shiftwidth=4 fileencoding=utf-8 noexpandtab: */

© Copyright 2020 Alexander J. Quinn         This content is protected and may not be shared, uploaded, or distributed.