-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
a9337b8
commit bf411a7
Showing
5 changed files
with
68 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,12 @@ | ||
import { Bits } from '../types' | ||
import circularShiftLeft from './circular-shift-left' | ||
|
||
test('CSHIFTL', () => { | ||
const bits1: Bits = [1, 0, 0, 0, 1, 1, 0, 1] | ||
const expected1: Bits = [0, 0, 0, 1, 1, 0, 1, 1] | ||
expect(circularShiftLeft(bits1)).toEqual(expected1) | ||
|
||
const bits2: Bits = [0, 0, 0, 1, 1, 1, 1, 1] | ||
const expected2: Bits = [0, 0, 1, 1, 1, 1, 1, 0] | ||
expect(circularShiftLeft(bits2)).toEqual(expected2) | ||
}) |
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,19 @@ | ||
import { Bits } from '../types' | ||
|
||
/** | ||
* Circular Shift Left | ||
* | ||
* @example | ||
* circularShiftLeft([1,0,1,1,0,1]) => [0,1,1,0,1,1] | ||
* | ||
* @param {Array} bits input data | ||
* @return {Array} [CSHIFTL bits] | ||
*/ | ||
export default (bits: Bits): Bits => { | ||
const result: Bits = [] | ||
|
||
for (let i: number = 1; i < bits.length; i++) result[i - 1] = bits[i] | ||
result[bits.length - 1] = bits[0] | ||
|
||
return result | ||
} |
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,12 @@ | ||
import { Bits } from '../types' | ||
import circularShiftRight from './circular-shift-right' | ||
|
||
test('CSHIFTR', () => { | ||
const bits1: Bits = [1, 0, 0, 0, 1, 1, 0, 1] | ||
const expected1: Bits = [1, 1, 0, 0, 0, 1, 1, 0] | ||
expect(circularShiftRight(bits1)).toEqual(expected1) | ||
|
||
const bits2: Bits = [0, 0, 0, 1, 1, 1, 1, 1] | ||
const expected2: Bits = [1, 0, 0, 0, 1, 1, 1, 1] | ||
expect(circularShiftRight(bits2)).toEqual(expected2) | ||
}) |
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,19 @@ | ||
import { Bits } from '../types' | ||
|
||
/** | ||
* Circular Shift Right | ||
* | ||
* @example | ||
* circularShiftRight([1,0,1,1,0,1]) => [1,1,0,1,1,0] | ||
* | ||
* @param {Array} bits input data | ||
* @return {Array} [CSHIFTR bits] | ||
*/ | ||
export default (bits: Bits): Bits => { | ||
const result: Bits = [] | ||
|
||
result[0] = bits.pop() | ||
for (let i: number = 0; i < bits.length; i++) result[i + 1] = bits[i] | ||
|
||
return result | ||
} |
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