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
29
30
31
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>

typedef struct _Point {
    short int x;  // 2 bytes
    short int y;  // 2 bytes
} Point;

int main(int argc, char* argv[]) {
    uint8_t bytes[] = { 0x59, 0x6f, 0x21, 0x00 };

    char* as_string = (char*)bytes;
    printf("%s\n", as_string);
    // Yo!

    int as_int = *(int*)bytes;
    printf("%d\n", as_int);
    // 2191193

    float as_float = *(float*)bytes;
    printf("%.64f\n", as_float);
    // 0.0000000000000000000000000000000000000030705153859392888920885798

    Point as_point = *(Point*)bytes;
    printf("(Point) { .x=%hd, .y=%hd }\n", as_point.x, as_point.y);
    // (Point) { .x=28505, .y=33 }

    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.