source:
utilitiespy/tudelft/utilities/tools/calc.py@
1303
Last change on this file since 1303 was 1207, checked in by , 8 weeks ago | |
---|---|
File size: 258 bytes |
Line | |
---|---|
1 | |
2 | |
3 | def truncate(n:int, nbits: int): |
4 | ''' |
5 | keep only the lowest nbits of n. This effectively keeps the number signed |
6 | but weird things will happen if n does not fit in nbits |
7 | ''' |
8 | half = 1<<(nbits-1) |
9 | return ((n+half)& ((1<<nbits)-1)) - half |
Note:
See TracBrowser
for help on using the repository browser.