-
Notifications
You must be signed in to change notification settings - Fork 8
added logical shift operations #45
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from 6 commits
8f2dc8c
c63f43c
4521baa
55a55af
a6240ab
1643cf8
1dbe2f1
e3af71b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import { Bits } from '../types' | ||
import lshiftl from './lshiftl' | ||
|
||
test('LSHIFTL', () => { | ||
const bits1: Bits = [1, 0, 0, 0, 1, 1, 0, 1] | ||
const expected1: Bits = [0, 0, 0, 1, 1, 0, 1, 0] | ||
expect(lshiftl(bits1)).toEqual(expected1) | ||
|
||
const bits2: Bits = [0, 0, 0, 1, 1, 1, 0, 0] | ||
const expected2: Bits = [0, 0, 1, 1, 1, 0, 0, 0] | ||
expect(lshiftl(bits2)).toEqual(expected2) | ||
}) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import { Bit, Bits } from '../types' | ||
|
||
/** | ||
* Logical Shift Left | ||
* | ||
* Shifts all given bits to left and returns the resulting bits | ||
* | ||
* @example | ||
* lshiftl([1,0,1,1,0,1]) => [0,1,1,0,1,0] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @0xflotus can you make a case for this not returning If you have a particular use-case in mind for the non-size-increasing version, we could also add a flag for this behavior. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There are 6 Bits in the example and you are referring to 7 Bits. Which case should it return? |
||
* | ||
* @param {Array} bits input data | ||
* @return {Array} [LSHIFTL bits] | ||
*/ | ||
export default (bits: Bits): Bits => { | ||
const result: Bits = [] | ||
|
||
for (let i: number = 0; i < bits.length - 1; i++) result.push(bits[i + 1]) | ||
result.push(<Bit>0) | ||
0xflotus marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
return result | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import { Bits } from '../types' | ||
import lshiftr from './lshiftr' | ||
|
||
test('LSHIFTR', () => { | ||
const bits1: Bits = [1, 0, 0, 0, 1, 1, 0, 1] | ||
const expected1: Bits = [0, 1, 0, 0, 0, 1, 1, 0] | ||
expect(lshiftr(bits1)).toEqual(expected1) | ||
|
||
const bits2: Bits = [0, 0, 0, 1, 1, 1, 0, 0] | ||
const expected2: Bits = [0, 0, 0, 0, 1, 1, 1, 0] | ||
expect(lshiftr(bits2)).toEqual(expected2) | ||
}) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import { Bit, Bits } from '../types' | ||
|
||
/** | ||
* Logical Shift Right | ||
* | ||
* Shifts all given bits to right and returns the resulting bits | ||
* | ||
* @example | ||
* lshiftr([1,0,1,1,0,1]) => [0,1,0,1,1,0] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not as concerned about this one, but I suppose it’s possible to argue that the leading There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. are you sure? |
||
* | ||
* @param {Array} bits input data | ||
* @return {Array} [LSHIFTR bits] | ||
*/ | ||
export default (bits: Bits): Bits => { | ||
const result: Bits = [] | ||
|
||
result.push(<Bit>0) | ||
0xflotus marked this conversation as resolved.
Show resolved
Hide resolved
|
||
for (let i: number = 0; i < bits.length - 1; i++) result.push(bits[i]) | ||
|
||
return result | ||
} |
Uh oh!
There was an error while loading. Please reload this page.