{"id":17996724,"url":"https://github.com/cosmo/binarykit","last_synced_at":"2026-02-27T06:02:08.915Z","repository":{"id":55120479,"uuid":"49175744","full_name":"Cosmo/BinaryKit","owner":"Cosmo","description":"💾🔍🧮 BinaryKit helps you to break down binary data into bits and bytes, easily access specific parts and write data to binary.","archived":false,"fork":false,"pushed_at":"2020-12-22T15:40:47.000Z","size":177,"stargazers_count":111,"open_issues_count":2,"forks_count":19,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-03-21T05:22:12.774Z","etag":null,"topics":["binary","binary-data","bit","bits","byte","bytes","data","hacktoberfest","nsdata","swift"],"latest_commit_sha":null,"homepage":"","language":"Swift","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Cosmo.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2016-01-07T02:31:00.000Z","updated_at":"2024-10-26T04:14:43.000Z","dependencies_parsed_at":"2022-08-14T12:40:14.567Z","dependency_job_id":null,"html_url":"https://github.com/Cosmo/BinaryKit","commit_stats":null,"previous_names":[],"tags_count":5,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Cosmo%2FBinaryKit","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Cosmo%2FBinaryKit/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Cosmo%2FBinaryKit/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Cosmo%2FBinaryKit/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Cosmo","download_url":"https://codeload.github.com/Cosmo/BinaryKit/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245589139,"owners_count":20640232,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["binary","binary-data","bit","bits","byte","bytes","data","hacktoberfest","nsdata","swift"],"created_at":"2024-10-29T21:15:41.403Z","updated_at":"2025-10-08T17:32:42.146Z","avatar_url":"https://github.com/Cosmo.png","language":"Swift","readme":"# BinaryKit\n\nBinaryKit helps you to break down binary data into bits and bytes, easily access specific parts and write data to binary.\n\n## Access Bytes\n\nBy using any `read*` method (`readByte()`, `readBytes(quantity:)`, `readBit()`, …), BinaryKit will increment an internal cursor (or reading offset) to the end of the requested bit or byte, so the next `read*` method can continue from there.\n\nAny `get*` method (`getByte(index:)`, `getBytes(range:)`, `getBit(index:)`, …) will give access to binary data at any given location — without incrementing the internal cursor.\n\nHere are the methods you can call:\n\n```swift\nvar binary = Binary(bytes: [0xDE, 0xAD, 0xBE, 0xEF, …])\n\n// Reads exactly 1 byte and\n// increments the cursor by 1 byte \ntry binary.readByte()\n\n// Reads the next 4 bytes and\n// increments the cursor by 4 bytes\ntry binary.readBytes(4)\n\n// Reads the next 1 bit and\n// increments the cursor by 1 bit\ntry binary.readBit()\n\n// Reads the next 4 bits and\n// increments the cursor by 4 bits\ntry binary.readBits(4)\n```\n\n### Example\n\n```swift\nvar binary = Binary(bytes: [0b1_1_0_1_1_1_0_0])\n//                            | | | | | | | | \n//                            | | | | | | | try binary.readBit()  // 0\n//                            | | | | | | try binary.readBit()    // 0\n//                            | | | | | try binary.readBit()      // 1\n//                            | | | | try binary.readBit()        // 1\n//                            | | | try binary.readBit()          // 1\n//                            | | try binary.readBit()            // 0\n//                            | try binary.readBit()              // 1\n//                            try binary.readBit()                // 1\n```\n\nThis shows how easy it is, to break down an [IPv4 header](https://en.wikipedia.org/wiki/IPv4#Header).\n\n```swift\nvar binary = Binary(bytes: [0x1B, 0x44, …])\nlet version                         = try binary.readBits(4)\nlet internetHeaderLength            = try binary.readBits(4)\nlet differentiatedServicesCodePoint = try binary.readBits(6)\nlet explicitCongestionNotification  = try binary.readBits(2)\nlet totalLength                     = try binary.readBytes(2)\nlet identification                  = try binary.readBytes(2)\nlet flags                           = try binary.readBits(4)\nlet fragmentOffset                  = try binary.readBits(12)\nlet timeToLive                      = try binary.readByte()\nlet protocolNumber                  = try binary.readByte()\nlet headerChecksum                  = try binary.readBytes(2)\nlet sourceIpAddress                 = try binary.readBytes(4)\nlet destinationIpAddress            = try binary.readBytes(4)\n...\n```\n\n## Store Bytes\n\nUse the `write*` methods to store different types to binary. \n\n```swift\nvar binary = Binary()\nbinary.writeInt32(1_350_849_546)\nbinary.writeString(\"Hello World!\")\nbinary.writeBytes([0xFF, 0xCC, 0x00, 0x01])\nbinary.writeBool(true)\n```\n\n## Contact\n\n* Devran \"Cosmo\" Uenal\n* Twitter: [@maccosmo](http://twitter.com/maccosmo)\n* LinkedIn: [devranuenal](https://www.linkedin.com/in/devranuenal)\n\n## Other Projects\n\n* [Clippy](https://github.com/Cosmo/Clippy) — Clippy from Microsoft Office is back and runs on macOS! Written in Swift.\n* [GrammaticalNumber](https://github.com/Cosmo/GrammaticalNumber) — Turns singular words to the plural and vice-versa in Swift.\n* [HackMan](https://github.com/Cosmo/HackMan) — Stop writing boilerplate code yourself. Let hackman do it for you via the command line.\n* [ISO8859](https://github.com/Cosmo/ISO8859) — Convert ISO8859 1-16 Encoded Text to String in Swift. Supports iOS, tvOS, watchOS and macOS.\n* [SpriteMap](https://github.com/Cosmo/SpriteMap) — SpriteMap helps you to extract sprites out of a sprite map. Written in Swift.\n* [StringCase](https://github.com/Cosmo/StringCase) — Converts String to lowerCamelCase, UpperCamelCase and snake_case. Tested and written in Swift.\n* [TinyConsole](https://github.com/Cosmo/TinyConsole) — TinyConsole is a micro-console that can help you log and display information inside an iOS application, where having a connection to a development computer is not possible.\n\n## License\n\nBinaryKit is released under the [MIT License](http://www.opensource.org/licenses/MIT).\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcosmo%2Fbinarykit","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcosmo%2Fbinarykit","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcosmo%2Fbinarykit/lists"}