aboutsummaryrefslogtreecommitdiffstats
path: root/int24.h
blob: a7c7c4cb6da41703f2653a8160c1a82d7c213df9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
#ifndef LIBUCD_INT24_H
#define LIBUCD_INT24_H 1

#include <inttypes.h>

typedef uint8_t int24[3];
typedef uint8_t uint24[3];

static inline uint32_t getuint24(const uint8_t *p)
{
  return (uint32_t)p[0] +
    ((uint32_t)p[1] << 8) +
    ((uint32_t)p[2] << 16);
}

static inline int32_t getint24(const uint8_t *p)
{
  return (int32_t)p[0] +
    ((int32_t)p[1] << 8) +
    ((int32_t)(int8_t)p[2] << 16);
}

#endif /* LIBUCD_INT24_H */