source: utilitiespy/tudelft/utilities/tools/calc.py@ 1404

Last change on this file since 1404 was 1207, checked in by wouter, 3 months ago

replaced asbyte with truncate which is more general

File size: 258 bytes
Line 
1
2
3def 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.