RetroArch
bit_ops.h
Go to the documentation of this file.
1 /*
2  bit_ops.h
3  Functions for dealing with conversion of data between types
4 
5  Copyright (c) 2006 Michael "Chishm" Chisholm
6 
7  Redistribution and use in source and binary forms, with or without modification,
8  are permitted provided that the following conditions are met:
9 
10  1. Redistributions of source code must retain the above copyright notice,
11  this list of conditions and the following disclaimer.
12  2. Redistributions in binary form must reproduce the above copyright notice,
13  this list of conditions and the following disclaimer in the documentation and/or
14  other materials provided with the distribution.
15  3. The name of the author may not be used to endorse or promote products derived
16  from this software without specific prior written permission.
17 
18  THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
19  WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
20  AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE
21  LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22  DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
23  LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24  THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25  (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
26  EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 */
28 
29 #ifndef _BIT_OPS_H
30 #define _BIT_OPS_H
31 
32 #include <stdint.h>
33 
34 /*-----------------------------------------------------------------
35 Functions to deal with little endian values stored in uint8_t arrays
36 -----------------------------------------------------------------*/
37 static inline uint16_t u8array_to_u16 (const uint8_t* item, int offset)
38 {
39  return ( item[offset] | (item[offset + 1] << 8));
40 }
41 
42 static inline uint32_t u8array_to_u32 (const uint8_t* item, int offset)
43 {
44  return ( item[offset] | (item[offset + 1] << 8) | (item[offset + 2] << 16) | (item[offset + 3] << 24));
45 }
46 
47 static inline void u16_to_u8array (uint8_t* item, int offset, uint16_t value)
48 {
49  item[offset] = (uint8_t) value;
50  item[offset + 1] = (uint8_t)(value >> 8);
51 }
52 
53 static inline void u32_to_u8array (uint8_t* item, int offset, uint32_t value)
54 {
55  item[offset] = (uint8_t) value;
56  item[offset + 1] = (uint8_t)(value >> 8);
57  item[offset + 2] = (uint8_t)(value >> 16);
58  item[offset + 3] = (uint8_t)(value >> 24);
59 }
60 
61 #endif /* _BIT_OPS_H */
static uint32_t u8array_to_u32(const uint8_t *item, int offset)
Definition: bit_ops.h:42
static void u32_to_u8array(uint8_t *item, int offset, uint32_t value)
Definition: bit_ops.h:53
static void u16_to_u8array(uint8_t *item, int offset, uint16_t value)
Definition: bit_ops.h:47
GLsizei const GLfloat * value
Definition: glext.h:6709
GLintptr offset
Definition: glext.h:6560
unsigned short uint16_t
Definition: stdint.h:125
static uint16_t u8array_to_u16(const uint8_t *item, int offset)
Definition: bit_ops.h:37
unsigned char uint8_t
Definition: stdint.h:124
unsigned int uint32_t
Definition: stdint.h:126