GithubHelp home page GithubHelp logo

cosmo / binarykit Goto Github PK

View Code? Open in Web Editor NEW
110.0 4.0 19.0 177 KB

๐Ÿ’พ๐Ÿ”๐Ÿงฎ BinaryKit helps you to break down binary data into bits and bytes, easily access specific parts and write data to binary.

License: MIT License

Swift 100.00%
swift bytes bit bits byte binary binary-data data nsdata hacktoberfest

binarykit's People

Contributors

aserdobintsev avatar cosmo avatar wacumov avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

binarykit's Issues

I'm sure I'm doing something wrong

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

Not all the tests run on Linux

Test cases that do not run on Linux:

  • testMixedReadByte
  • testMixedReadBytes
  • testReadBytesThrowsBeforeReading
  • testReadBitsThrowsBeforeReading
  • testBool

Mixed writing behaviour

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'.

Mixed reading error

I'm getting wrong data while reading with using readBit() and readByte() methods, though readBitCursor increments correctly.

Test case:

  1. The data is 0b1010_1101_1010_1111.
  2. Do try bin.readBit() result 1
  3. Do try bin.readByte()
    Actual result: 173
    Expected result: 91

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

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.