Skip to content

Commit

Permalink
Added toBinary method to Bit
Browse files Browse the repository at this point in the history
  • Loading branch information
ankane committed Sep 18, 2024
1 parent bdec425 commit c523ae9
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions lib/src/bit.dart
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,19 @@ class Bit {
return Bit._(length, bytes.sublist(4));
}

Uint8List toBinary() {
var bytes = new Uint8List(4 + ((_len + 7) / 8).toInt());
var buf = new ByteData.view(bytes.buffer, bytes.offsetInBytes);

buf.setInt32(0, _len);

for (var i = 0; i < _data.length; i++) {
buf.setUint8(4 + i, _data[i]);
}

return bytes;
}

List<bool> toList() {
var vec = <bool>[];
for (var i = 0; i < _len; i++) {
Expand Down

0 comments on commit c523ae9

Please sign in to comment.