Repository navigation
Modern Math BitWidth
Paul Squires edited this page Oct 19, 2026
·
5 revisions
Home › Math Library › Math Library › BitWidth
Returns how many bits the value needs, or 0 for zero.
BitWidth( byval x as T ) as int32- One more than the index of the highest set bit, so it is the width of the value rather than of the type.
- Zero needs 0 bits, which is the convention that makes
BitWidthandNextPow2agree. - It is the type's width minus
LeadingZeros.
#import "std/numeric"
using numeric
dim as uint32 x = 8
print BitWidth( x ) '' 4 -- 1000 needs four bits
dim as uint32 y = 7
print BitWidth( y ) '' 3 -- 111 needs three
dim as uint32 zero_ = 0
print BitWidth( zero_ ) '' 0 -- zero needs noneLibrary: Math Library
Category: Math Library
Documented under: Members
tiko-lang · Home · Feature Index · Keyword Index · License
FreeBASIC manual pages reproduced under the GNU FDL 1.3.
- Generics
- Interfaces
- For Each
- Iterators
- Tuples
- Array Results
- Defer
- Lambdas
- Block Strings
- Partial Types
- String Slices
- Embed
- Typed Variadics
- C Header Import
- Foreign Library Linking
- UString
- Fixed-Width Types
- Nullptr
- String Library
- Format
- Array
- Map
- Set
- LinkedList
- OrderedMap
- OrderedSet
- Sorting
- Optional
- Result
- Smart Pointers
- Date and Time (Chrono)
- Filesystem
- File Streams
- Config (INI and TOML)
- Codec
- Hash
- UUID
- OS
- Process
- Net
- HTTP and TLS
- Math Library
- Finance
- Logging
- Terminal TUI Library
- PsControls
- tkControls
- sys/win
- Goroutines and Channels
- LLVM Backend
- tiko build
- TIKO_COMPILER
- Variable Declarations
- Standard Data Types
- User Defined Types
- Procedures
- Operators
- Control Flow Statements
- Converting Data Types
- Array Functions
- String Functions
- Mathematical Functions
- Bit Manipulation
- Date and Time Functions
- File I/O Functions
- Console Functions
- User Input (Runtime Library)
- User Input Functions (Graphics Library)
- Screen Functions
- 2D Drawing Functions
- Graphics Library Reference
- Graphics Keyword List
- Memory Functions
- Threading Support Functions
- Error Handling Functions
- Operating System Functions
- Preprocessor
- Intrinsic Defines
- Miscellaneous Keywords
- Modularizing