1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
#include <assert.h>

int main(int argc, char* argv[]) {
    // int n = 111;   // The RHS (right-hand side) is an integer literal in base 10.
                   // The variable `n` is just a quantity.  It has no number base.
    
    // int n = 0157;    // Notation:  Prefix with "0"  to express in octal
    // int n = 0x6f;    // Notation:  Prefix with "0x" to express in hexadecimal
    int n = 0x60 + 0x0f;  // Hexadecimal:  digits are 0 to f.
    // What is 0x0f?  The rightmost digit is always the 1 digit because 
    //   ▒^0 is 1
    // f stands for 15
    // 0 1 2 3 4 5 6 7 8 9  a  b  c  d  e  f    ←  hexadecimal digit
    // 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15    ←  value written in decimal
    // 
    // What is 0x60?  The '6' is in the 16s place, which is 16¹.
    // The value of 0x60 is "ninety-six".

    printf("n is %d (written in base 10)\n", n);  // d in %d stands for decimal
    printf("n is %o (written in base  8)\n", n);  // o in %o stands for octal
    printf("n is %x (written in base 16)\n", n);  // x in %x stands for heXadecimal

    return EXIT_SUCCESS;
}
/* vim: set tabstop=4 shiftwidth=4 fileencoding=utf-8 noexpandtab: */

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