cosmo / binarykit Goto Github PK
View Code? Open in Web Editor NEW๐พ๐๐งฎ BinaryKit helps you to break down binary data into bits and bytes, easily access specific parts and write data to binary.
License: MIT License
๐พ๐๐งฎ BinaryKit helps you to break down binary data into bits and bytes, easily access specific parts and write data to binary.
License: MIT License
I'm sure I'm doing something wrong, could you point me right direction please? Im trying to read signed value but not sure how to correctly read negative one.
I added category to accomplish this
extension Binary {
mutating func readSignedBits(quantitiy: Int) throws -> Int {
if try readBit() == 1 {
let bit = try readBits(quantitiy: quantitiy - 1)
let bitsReversed = String(String(bit, radix: 2).map({ $0 == "1" ? "0" : "1" }))
return -Int(bitsReversed, radix: 2)! - 1
} else {
return try readBits(quantitiy: quantitiy - 1)
}
}
}
but it doesn't "feel" right
Test cases that do not run on Linux:
Hi Devran, could you help me to understand, is it intended writing behaviour that divides writing with bits and bytes?
For example:
var bin = Binary(bytes: [])
bin.writeBit(bit: 1)
bin.writeByte(8)
I would expect the binary is 0b1000_0100_0000_0000
- padded with zeros to the end of the byte.
The Actual result is 0b1000_0000_0000_1000
- written byte adde as next but bit cursor still points to the position '1'.
I'm getting wrong data while reading with using readBit()
and readByte()
methods, though readBitCursor
increments correctly.
Test case:
0b1010_1101_1010_1111
.try bin.readBit()
result 1try bin.readByte()
The expected behaviour is that Binary
reads sequentially:
// readBitCursor // 9
// |
var binary = Binary(bytes: [0b1_1011100, 0b1_0101111])
// | |___________|
// | |
// | try binary.readBit() // 91
// try binary.readBit() // 1
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.