Last active
August 29, 2015 13:56
-
-
Save itsthatguy/9166257 to your computer and use it in GitHub Desktop.
A few functions to help you test your bitwise operations
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
Foo = require("./foo.coffee") | |
describe 'Foo', -> | |
testOpts = | |
initialNumber: 255 | |
initialArray: [255,255,255] | |
expectedBinary: 10010010101110101000 | |
it 'should return a correct binary string', -> | |
foo = new Foo() | |
binary = foo.intToBinary(testOpts.initialNumber) | |
binary.should.equal "11111111" | |
it 'should return a correct hexadecimal string', -> | |
foo = new Foo() | |
binary = foo.intToHexadecimal(testOpts.initialNumber) | |
binary.should.equal "ff" | |
it 'should return a correct binary string from an array', -> | |
foo = new Foo() | |
binary = foo.arrayToBinary(testOpts.initialArray) | |
binary.should.equal "111111111111111111111111" | |
it 'should return a correct hexadecimal string from an array', -> | |
foo = new Foo() | |
binary = foo.arrayToHexadecimal(testOpts.initialArray) | |
binary.should.equal "ffffff" |
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
class Foo | |
arrayToBinary: (array) -> (array.map (n) => @intToBinary(n)).join('') | |
arrayToHexadecimal: (array) -> (array.map (n) => @intToHexadecimal(n)).join('') | |
intToHexadecimal: (number) -> return parseInt(number).toString(16) | |
intToBinary: (number) -> return parseInt(number).toString(2) | |
module.exports = Foo |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment