File: intutil.h

package info (click to toggle)
ruby-liquid-c 4.2.0-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 504 kB
  • sloc: ansic: 3,866; ruby: 1,151; makefile: 7
file content (22 lines) | stat: -rw-r--r-- 426 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
#ifndef LIQUID_INTUTIL_H
#define LIQUID_INTUTIL_H

#include <stdint.h>

static inline unsigned int bytes_to_uint24(const uint8_t *bytes)
{
    return (bytes[0] << 16) | (bytes[1] << 8) | bytes[2];
}

static inline void uint24_to_bytes(unsigned int num, uint8_t *bytes)
{
    assert(num < (1 << 24));

    bytes[0] = num >> 16;
    bytes[1] = num >> 8;
    bytes[2] = num;

    assert(bytes_to_uint24(bytes) == num);
}

#endif