mirror of
https://github.com/obgm/libcoap.git
synced 2026-10-31 06:55:47 +03:00
Carsten\'s encode functions for pseudo-fp
This commit is contained in:
1 parent
b325dfbdd4
commit
d91feeb790
2 files changed
+25
-27
No files matched your search
@@ -1,6 +1,6 @@
|
||||
/* encode.c -- encoding and decoding of CoAP data types
|
||||
*
|
||||
* (c) 2010 Olaf Bergmann <bergmann@tzi.org>
|
||||
* (c) 2010 Carsten Bormann
|
||||
*/
|
||||
|
||||
#ifndef NDEBUG
|
||||
@@ -9,24 +9,11 @@
|
||||
|
||||
#include "encode.h"
|
||||
|
||||
unsigned int
|
||||
coap_pseudo_encode( unsigned int val ) {
|
||||
unsigned int e = 0;
|
||||
|
||||
if ( val < HIBIT )
|
||||
return val;
|
||||
|
||||
if ( val > MAX_VALUE ) {
|
||||
#ifndef NDEBUG
|
||||
fprintf(stderr, "cannot encode value %u\n", val);
|
||||
#endif
|
||||
return ( 1 << N ) - 1;
|
||||
}
|
||||
|
||||
while ( HIBIT < (val & ~0xff) ) {
|
||||
val = val >> 1;
|
||||
e += 1;
|
||||
}
|
||||
|
||||
return (val & ~EMASK) | e;
|
||||
/* Carsten suggested this when fls() is not available: */
|
||||
int coap_fls(unsigned int i) {
|
||||
int n;
|
||||
for (n = 0; i; n++)
|
||||
i >>= 1;
|
||||
return n;
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user