bit-array
Advanced tools
Comparing version 0.1.3 to 0.1.5
/** | ||
* JavaScript BitArray - v0.1.1 | ||
* | ||
* JavaScript BitArray - v0.1.5 | ||
* | ||
* Licensed under the revised BSD License. | ||
* Copyright 2010 Bram Stein | ||
* Copyright 2010-2012 Bram Stein | ||
* All rights reserved. | ||
@@ -127,7 +127,8 @@ */ | ||
BitArray.prototype.toHexString = function () { | ||
return this.values.map(function (value) { | ||
// Prepend with zeroes: 0000aaaa 0000bbbb is different than aaaabbbb | ||
// Do a bit shift no-op to force this value to be treated as unsigned. | ||
return ('00000000' + (value >>> 0).toString(16)).slice(-8); | ||
}).join(''); | ||
var result = []; | ||
for (var i = 0; i < this.values.length; i += 1) { | ||
result.push(('00000000' + (this.values[i] >>> 0).toString(16)).slice(-8)); | ||
} | ||
return result.join(''); | ||
}; | ||
@@ -134,0 +135,0 @@ |
{ | ||
"name": "bit-array", | ||
"description": "JavaScript implementation of bit arrays", | ||
"version": "0.1.3", | ||
"version": "0.1.5", | ||
"author": "Bram Stein <b.l.stein@gmail.com> (http://www.bramstein.com)", | ||
@@ -6,0 +6,0 @@ "repository": { |
@@ -35,2 +35,5 @@ ## JavaScript Bit Array Library | ||
<dd>Creates a new empty bit array.</dd> | ||
<dt>BitArray(string)</dt> | ||
<dd>Creates a new bit array using the hex values in the string</dd> | ||
@@ -71,2 +74,5 @@ <dt>BitArray([integer, ...])</dt> | ||
<dt>toHexString()</dt> | ||
<dd>Returns a hex representation of the BitArray.</dd> | ||
<dt>valueOf()</dt> | ||
@@ -73,0 +79,0 @@ <dd>Returns the internal representation of the BitArray.</dd> |
@@ -21,5 +21,5 @@ var assert = require('assert'), | ||
assert.equal(b.toString(), '0000000010100000000000000000011000000000000001101000000000000000', 'BitArray([..])'); | ||
var c = new BitArray([0xffffeeee, 0xddddcccc]); | ||
assert.equal(c.toHexString(), 'ffffeeeeddddcccc'); | ||
@@ -37,6 +37,6 @@ }; | ||
assert.equal(b.toHexString(), 'deadbeef', 'BitArray(0x...)'); | ||
// Test zero-padding | ||
var c = new BitArray('c0ffeec0ffee').and(new BitArray('ffffffffff000000')); | ||
assert.equal(c.toHexString(), '0000c0ffee000000', 'BitArray(0x...)'); | ||
@@ -80,3 +80,3 @@ }; | ||
b.set(32, true); | ||
assert.equal(b.size(), 64, 'set(32, true).size()'); | ||
@@ -86,2 +86,13 @@ assert.equal(b.toString(), '0000000000000000000000000000000010000000000000000000000000000000', 'set(32, true).toString()'); | ||
exports.testToHexString = function () { | ||
var b = new BitArray() | ||
b.set(512, true); | ||
assert.equal(b.toHexString(), '0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001'); | ||
}; | ||
exports.testToHexStringConstructor = function () { | ||
var b = new BitArray('deadbeef'); | ||
assert.equal(b.toHexString(), 'deadbeef'); | ||
}; | ||
exports.testSimpleGet = function () { | ||
@@ -88,0 +99,0 @@ var b = new BitArray(); |
17255
431
116