forked from novnc/noVNC
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add util for unsigned and signed int. conversion
Will be used in later commit in extended clipboard handling.
- Loading branch information
1 parent
f52e979
commit 9575ded
Showing
2 changed files
with
31 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
/* | ||
* noVNC: HTML5 VNC client | ||
* Copyright (C) 2020 The noVNC Authors | ||
* Licensed under MPL 2.0 (see LICENSE.txt) | ||
* | ||
* See README.md for usage and integration instructions. | ||
*/ | ||
|
||
export function toUnsigned32bit(toConvert) { | ||
return toConvert >>> 0; | ||
} | ||
|
||
export function toSigned32bit(toConvert) { | ||
return toConvert | 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
/* eslint-disable no-console */ | ||
const expect = chai.expect; | ||
|
||
import { toUnsigned32bit, toSigned32bit } from '../core/util/int.js'; | ||
|
||
describe('Integer casting', function () { | ||
it('should cast unsigned to signed', function () { | ||
let expected = 4294967286; | ||
expect(toUnsigned32bit(-10)).to.equal(expected); | ||
}); | ||
|
||
it('should cast signed to unsigned', function () { | ||
let expected = -10; | ||
expect(toSigned32bit(4294967286)).to.equal(expected); | ||
}); | ||
}); |