2016-08-15 18:16:30 +08:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2016 Nordic Semiconductor ASA
|
|
|
|
* Copyright (c) 2016 Vinayak Kariappa Chettimada
|
|
|
|
*
|
2017-01-19 09:01:01 +08:00
|
|
|
* SPDX-License-Identifier: Apache-2.0
|
2016-08-15 18:16:30 +08:00
|
|
|
*/
|
|
|
|
|
Introduce new sized integer typedefs
This is a start to move away from the C99 {u}int{8,16,32,64}_t types to
Zephyr defined u{8,16,32,64}_t and s{8,16,32,64}_t. This allows Zephyr
to define the sized types in a consistent manor across all the
architectures we support and not conflict with what various compilers
and libc might do with regards to the C99 types.
We introduce <zephyr/types.h> as part of this and have it include
<stdint.h> for now until we transition all the code away from the C99
types.
We go with u{8,16,32,64}_t and s{8,16,32,64}_t as there are some
existing variables defined u8 & u16 as well as to be consistent with
Zephyr naming conventions.
Jira: ZEP-2051
Change-Id: I451fed0623b029d65866622e478225dfab2c0ca8
Signed-off-by: Kumar Gala <kumar.gala@linaro.org>
2017-04-19 23:32:08 +08:00
|
|
|
#include <zephyr/types.h>
|
2016-08-15 18:16:30 +08:00
|
|
|
#include "util.h"
|
|
|
|
|
2017-04-21 01:00:29 +08:00
|
|
|
u8_t util_ones_count_get(u8_t *octets, u8_t octets_len)
|
2016-08-15 18:16:30 +08:00
|
|
|
{
|
2017-04-21 01:00:29 +08:00
|
|
|
u8_t one_count = 0;
|
2016-08-15 18:16:30 +08:00
|
|
|
|
|
|
|
while (octets_len--) {
|
2017-04-21 01:00:29 +08:00
|
|
|
u8_t bite;
|
2016-08-15 18:16:30 +08:00
|
|
|
|
|
|
|
bite = *octets;
|
|
|
|
while (bite) {
|
|
|
|
bite &= (bite - 1);
|
|
|
|
one_count++;
|
|
|
|
}
|
|
|
|
octets++;
|
|
|
|
}
|
|
|
|
|
|
|
|
return one_count;
|
|
|
|
}
|