{"id":13535150,"url":"https://github.com/DrAma999/BitWiser","last_synced_at":"2025-04-02T00:32:38.670Z","repository":{"id":44569647,"uuid":"442802109","full_name":"DrAma999/BitWiser","owner":"DrAma999","description":"A simple library to help you in dealing with bytes, bits and nibbles :-)","archived":false,"fork":false,"pushed_at":"2022-02-08T08:10:00.000Z","size":302,"stargazers_count":25,"open_issues_count":0,"forks_count":2,"subscribers_count":3,"default_branch":"main","last_synced_at":"2024-03-14T13:42:13.358Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"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/DrAma999.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":"2021-12-29T14:45:19.000Z","updated_at":"2024-01-16T16:23:41.000Z","dependencies_parsed_at":"2022-07-25T23:03:01.283Z","dependency_job_id":null,"html_url":"https://github.com/DrAma999/BitWiser","commit_stats":null,"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DrAma999%2FBitWiser","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DrAma999%2FBitWiser/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DrAma999%2FBitWiser/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DrAma999%2FBitWiser/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/DrAma999","download_url":"https://codeload.github.com/DrAma999/BitWiser/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246735354,"owners_count":20825221,"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":[],"created_at":"2024-08-01T08:00:50.446Z","updated_at":"2025-04-02T00:32:38.189Z","avatar_url":"https://github.com/DrAma999.png","language":"Swift","funding_links":[],"categories":["Data"],"sub_categories":[],"readme":"\u003cp align=\"center\"\u003e\n  \u003cimg width=\"200\" height=\"200\" src=\"README/Icon.png\"\u003e\n\u003c/p\u003e\n\n![Swift](https://github.com/DrAma999/LittleBlueTooth/workflows/Swift/badge.svg?branch=master)\n[![codecov](https://codecov.io/gh/DrAma999/BitWiser/branch/main/graph/badge.svg?token=Y3TXZ5NQN7)](https://codecov.io/gh/DrAma999/BitWiser)\n[![CodeFactor](https://www.codefactor.io/repository/github/drama999/bitwiser/badge/main)](https://www.codefactor.io/repository/github/drama999/bitwiser/overview/main)\n\n\n# BitWiser\n\nBitwiser is a collection of methods and properties that makes you work with `bits`, `bytes` and `nibbles` a piece of cake\n\nThe project is in early stages of development feel free to make pull requests for more funcionalities\n\n## FEATURES\n* No more bit masking. Access single bit values \n* Coverting from bytes array to `Data` and back has never been easier\n* Nice DSL for creating byte array and `Data`\n* Print `Data` into hex string\n* Set, reset, query, toggle each bit\n* Subscript\n* Chaining methods\n* Extensive code coverage\n* Multiplatform: iOS, macOS, tvOS, watchOS, Linux, Windows\n\n## INSTALLATION\nUse Swift package manager.\nAdd the following dependency to your Package.swift file:\n```\n.package(url: \"https://github.com/DrAma999/BitWiser.git\", from: \"0.0.2\")\n```\nOr simply add the URL from XCode menu Swift packages.\n\n## HOW TO USE IT\nA `Byte` is simply a `UInt8` that has been extended to access single bit values.\nA `Bit` is an enumeration that can assume two values `.one` or `.zero`.\n```\n var value = Byte(0b1010_1010)\n let bits = value.bits \n print(bits)\n // [0, 1, 0, 1, 0, 1, 0, 1]\n```\n**Note:** Bits representation is shown as an array of `Bit` where the array index 0 represents the **least significant bit** \n\nAfter creating a `Byte` you can read in its position in different ways:\n_Subscript_\n```\nlet bit = value[0]\n```\n_Method_\n```\n// Query the value\nlet bit = value.bit(0)\n// Ask if bit is set (equal to one)\nlet isSet = value.isBitSet(0)\n```\n_Properties_\n```\nlet bit = value.b0\n```\nAfter creating a  mutable `Byte` you can write in its position in different ways:\n_Subscript_\n```\nvalue[0] = 1\n```\n_Method_\n```\n// Set the specified bit to 1\nvalue.setBit(0)\n// Reset the specified bit to 0\nvalue.resetBit(0)\n// Toggle the specified bit. If the bit in position zero is one it becomes zero and viceversa\nvalue.toggleBit(0)\n// Change the value of the specified bit to one\nvalue.changeBit(0, to: .one )\n\n// Chaining modifiers that return a new value without mutating\nlet newValue = value\n              .settingBit(0)\n              .resettingBit(3)\n              .togglingBit(4)\n\n```\n_Properties_\n```\nvalue.b0 = .zero\n```\n\nPretty sure that if you worked in IOT you had an embedded engineer that put some infomration inside a nibble.\nWith bit wiser you can extract nibbles from a byte:\n```\n let value: Byte = 0b01011111\n let (msb, lsb) = value.nibbles\n```\n\nThere are also a lot of methods and facilities to work with bit bites and nibbles.\n\n## DSL\nBitWiser provides a DSL for creating byte arrays or `Data` objects.\nDSL is compatible with `if` `else` and `for` and is compatible with any object that conforms to `DataRepresentable`.\nHere and example to create a `Data` object:\n```\nData {\n        [UInt8(0)]\n        UInt8(1)\n        Int8(2)\n        \"\\u{03}\"\n        Int16(1284)\n        if dataClause {\n            CustomData()\n        }\n    }\n```\nand a byte array:\n```\nArray\u003cByte\u003e {\n            0b1010_1010\n            0b1100_1100\n            UInt8(32)\n            [0x05, 0x06]\n            Byte(0x01)\n        }\n```\n\n## CONTRIBUTING\nSince I'm working on this project in my spare time any help is appreciated.\nFeel free to make a pull request.\n\n## THANKS\n\nIcon made by  [Freepik](https://www.flaticon.com/authors/freepik)  from  [www.flaticon.com](http://www.flaticon.com/) \n\n## LICENSE\nMIT License\n\nCopyright (c) 2021 Andrea Finollo\n\nPermission is hereby granted, free of charge, to any person obtaining a copy\nof this software and associated documentation files (the \"Software\"), to deal\nin the Software without restriction, including without limitation the rights\nto use, copy, modify, merge, publish, distribute, sublicense, and/or sell\ncopies of the Software, and to permit persons to whom the Software is\nfurnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all\ncopies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\nIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\nFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\nAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\nLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\nOUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\nSOFTWARE.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FDrAma999%2FBitWiser","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FDrAma999%2FBitWiser","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FDrAma999%2FBitWiser/lists"}