Skip to content

Commit

Permalink
Comment check on top-most signed bit
Browse files Browse the repository at this point in the history
  • Loading branch information
jacogr committed Aug 22, 2023
1 parent 26dbfb4 commit ff9d02a
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions packages/util/src/u8a/toNumber.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ interface ToNumberOptions {
export function u8aToNumber (value: Uint8Array, { isNegative = false }: ToNumberOptions = {}): number {
const count = value.length;

// When the value is a i{8, 16, 24, 32, 40, 40} values and the top-most bit
// indicates a signed value, we use a two's complement conversion. If one of these
// flags are not set, we just do a normal unsigned conversion (the same shortcut
// applies in both the u8aTo{BigInt, Bn} conversions as well)
if (isNegative && (value[count - 1] & 0x80)) {
switch (count) {
case 0:
Expand Down

0 comments on commit ff9d02a

Please sign in to comment.