-
Notifications
You must be signed in to change notification settings - Fork 0
/
arm_inlines_gray.h
50 lines (40 loc) · 1.03 KB
/
arm_inlines_gray.h
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
/*!\file arm_inlines_gray.h
** \author SMFSW
** \copyright MIT (c) 2017-2024, SMFSW
** \brief Gray code conversion inlines
*/
/****************************************************************/
#ifndef ARM_INLINES_GRAY_H_
#define ARM_INLINES_GRAY_H_
#ifdef __cplusplus
extern "C" {
#endif
/****************************************************************/
/*!\brief Convert binary value to gray code
** \param[in] bin - binary value
** \return Converted value (gray code)
**/
__INLINE DWORD INLINE__ bin2gray(const DWORD bin)
{
return (RSHIFT(bin, 1U) ^ bin);
}
/*!\brief Convert gray code to binary value
** \param[in] gray - gray code value
** \return Converted value (binary)
**/
__INLINE DWORD gray2bin(const DWORD gray)
{
uintCPU_t bits = 32;
DWORD tmp = gray;
while ((bits >>= 1U) != 0U)
{
tmp ^= (tmp >> bits);
}
return tmp;
}
/****************************************************************/
#ifdef __cplusplus
}
#endif
#endif /* ARM_INLINES_GRAY_H_ */
/****************************************************************/