KM3NeT CLB  2.0
KM3NeT CLB v2 Embedded Software
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
func.c
1 /*
2  * KM3NeT CLB v2 Firmware
3  * ----------------------
4  *
5  * Copyright 2012-2016 KM3NeT Collaboration
6  *
7  * All Rights Reserved.
8  *
9  *
10  * File : func.c
11  * Created : 7 apr. 2016
12  * Author : Vincent van Beveren
13  */
14 
15 #include "util/func.h"
16 
17 int clz(uint32_t val)
18 {
19  int t = 0;
20  if ((val & 0xFFFF0000) == 0) t += 16; else val >>= 16;
21  if ((val & 0x0000FF00) == 0) t += 8; else val >>= 8;
22  if ((val & 0x000000F0) == 0) t += 4; else val >>= 4;
23  if ((val & 0x0000000C) == 0) t += 2; else val >>= 2;
24  if ((val & 0x00000002) == 0) t += 1;
25  return t;
26 }
27 
int clz(uint32_t val)
Count the leading zero's.
Definition: func.c:17
Various useful functions.