https://github.com/alja7dali/swift-bits
A bite sized library for dealing with bytes.
https://github.com/alja7dali/swift-bits
binary bit bits byte bytes comprehension data manipulation swift
Last synced: 3 months ago
JSON representation
A bite sized library for dealing with bytes.
- Host: GitHub
- URL: https://github.com/alja7dali/swift-bits
- Owner: Alja7dali
- License: mit
- Created: 2021-02-19T14:11:19.000Z (about 5 years ago)
- Default Branch: master
- Last Pushed: 2021-02-19T14:13:15.000Z (about 5 years ago)
- Last Synced: 2025-01-16T19:51:25.518Z (about 1 year ago)
- Topics: binary, bit, bits, byte, bytes, comprehension, data, manipulation, swift
- Language: Swift
- Homepage:
- Size: 6.84 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE.md
Awesome Lists containing this project
README
###### This is a modified forked repo of [Vapor-Bits](https://github.com/vapor-community/bits)
###### Why it been modified, because it serve a specific purpose `working with bytes only`. No need for the extra stuff that the original repo has, they can be in separate repo.
#### Example:
```swift
import Bits
let meaningOfLife: Double = -42.0
let bytes = meaningOfLife.makeBytes()
print(bytes) // [0, 0, 0, 0, 0, 0, 69, 192]
do {
let float = try Float(bytes)
} catch {
print(error) // BytesConversionError.invalidConversion(to: Swift.Float)
}
print(Bytes(-42.0 as Float)) // [0, 0, 40, 194]
if let double = try? Double(bytes) {
print(double) // -42.0
}
```
#### Importing Bits:
To include `Bits` in your project, you need to add the following to the `dependencies` attribute defined in your `Package.swift` file.
```swift
dependencies: [
.package(url: "https://github.com/alja7dali/swift-bits.git", from: "1.0.0")
]
```