mirror of
https://github.com/pybricks/pybricks-code.git
synced 2026-09-12 09:36:27 +00:00
implement flashing firmware from new zip format
This commit is contained in:
@@ -0,0 +1,27 @@
|
||||
/**
|
||||
* Compute modulo using floored division
|
||||
* @param a first operand
|
||||
* @param b second operand
|
||||
*/
|
||||
export function fmod(a: number, b: number): number {
|
||||
let c = a % b;
|
||||
if (c / b < 0) {
|
||||
c += b;
|
||||
}
|
||||
return c;
|
||||
}
|
||||
|
||||
/**
|
||||
* Calculates the 32-bit "sum complement" checksum
|
||||
* @data an iterable of 32-bit integers
|
||||
* @returns the value that needs to be added to get 0
|
||||
*/
|
||||
export function sumComplement32(data: Iterable<number>): number {
|
||||
let total = 0;
|
||||
for (const n of data) {
|
||||
total += n;
|
||||
total &= ~0;
|
||||
}
|
||||
// checksum is two's complement of total
|
||||
return ~total + 1;
|
||||
}
|
||||
Reference in New Issue
Block a user