|
|
@@ -9,15 +9,27 @@
|
|
|
import Foundation
|
|
|
|
|
|
extension Byte {
|
|
|
+
|
|
|
+ init(bits: [Bit]) {
|
|
|
+ var bitPattern:Byte = 0
|
|
|
+ for (idx,b) in enumerate(bits) {
|
|
|
+ if (b == Bit.Zero) {
|
|
|
+ var bit:Byte = Byte(1) << Byte(idx)
|
|
|
+ bitPattern = bitPattern | bit
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ self.init(bitPattern)
|
|
|
+ }
|
|
|
|
|
|
/** array of bits */
|
|
|
- internal func bits() -> [Bit] {
|
|
|
- let totalBitsCount = sizeof(Byte) * 8
|
|
|
+ func bits() -> [Bit] {
|
|
|
+ let totalBitsCount = sizeofValue(self) * 8
|
|
|
|
|
|
- var bitsArray:[Bit] = [Bit](count: totalBitsCount, repeatedValue: Bit.Zero)
|
|
|
+ var bitsArray = [Bit](count: totalBitsCount, repeatedValue: Bit.Zero)
|
|
|
|
|
|
for j in 0..<totalBitsCount {
|
|
|
- let bitVal:Byte = 1 << UInt8(totalBitsCount - 1 - j)
|
|
|
+ let bitVal:Byte = 1 << Byte(totalBitsCount - 1 - j)
|
|
|
let check = self & bitVal
|
|
|
|
|
|
if (check != 0) {
|
|
|
@@ -26,8 +38,8 @@ extension Byte {
|
|
|
}
|
|
|
return bitsArray
|
|
|
}
|
|
|
-
|
|
|
- internal func bits() -> String {
|
|
|
+
|
|
|
+ func bits() -> String {
|
|
|
var s = String()
|
|
|
let arr:[Bit] = self.bits()
|
|
|
for (idx,b) in enumerate(arr) {
|