summaryrefslogtreecommitdiff
path: root/man/ibits_len.3mpu
blob: 50e19daedb62b449acf85347b4cf6676228432f7 (plain)
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
.\" Copyright 2026 Andrew V.Kosteltsev (kx@radix-linux.su)
.\"
.\"
.TH ibits_len 3  "September 14, 2026" "libmpu" "LibMPU Programmer's Manual"
.SH NAME
\fBibits_len\fP \- bit length of an unsigned integer
.SH SYNOPSIS
.nf
.B #include <libmpu.h>
.PP
.BI "int ibits_len( mpu_int *" a ", int " nb " );"
.fi
.SH DESCRIPTION
The \fBibits_len()\fP function returns the number of significant bits required to represent
the unsigned integer located at address \fBa\fP. For a nonzero value this is the position of
the most significant set bit, counting the least significant bit as position 1. For zero,
the function returns 0.
.PP
The memory contents at address \fBa\fP are not changed. The \fBnb\fP parameter determines
the size of the operand, in bytes, and should be one of the integer sizes defined by
\fBlibmpu.h\fP (for example, \fBNB_I8\fP, \fBNB_I16\fP, ..., \fBNB_I65536\fP).
.PP
The function does not change the integer operation flags.
.sp
.SH EXAMPLES
.nf
.sp
#include <libmpu.h>
#include <stdio.h>

int main( void )
{
  mpu_int1024_t  a;
  int            nb = NB_I1024;

  __mpu_init();

  iatoui( a, "89000000000000", nb );
  printf( "nbits = %d;\\n", ibits_len( a, nb ) ); /* nbits = 47; */

  __mpu_free_context();

  return( 0 );
}
.fi
.sp
.SH SEE ALSO
.BR _int_digs(3),
.BR libmpu(7).