Sha256: ceece8e5ede270d3841f0fe7f016b2d59c4c86f362954b0054da6a95f6919de6

Contents?: true

Size: 867 Bytes

Versions: 366

Compression:

Stored size: 867 Bytes

Contents

extension Int {
    init(_ value: Binary?) {
        if let value = value {
            self = value.toDecimal
        } else {
            self = 0 }
    }
}
struct Binary {
    private var UIntValue: UInt = 0
    fileprivate var toDecimal: Int {
        return Int(UIntValue)
    }

    private func bi2Uint(_ input: String) -> UInt? {
        let orderedInput = Array(input.characters.reversed())
        var tempUInt: UInt = 0
        for (inx, each) in orderedInput.enumerated() {
            if each == "1" {
                tempUInt += UInt(0x1 << inx)
            }
            if each != "0" && each != "1" {
                return nil
            }
        }
        return tempUInt
    }

    init?(_ input: String) {
        if bi2Uint(input) != nil {
            self.UIntValue = bi2Uint(input)!
        } else {
            return nil
        }
    }
}

Version data entries

366 entries across 366 versions & 1 rubygems

Version Path
trackler-2.2.1.180 tracks/swift/exercises/binary/Sources/BinaryExample.swift
trackler-2.2.1.179 tracks/swift/exercises/binary/Sources/BinaryExample.swift
trackler-2.2.1.178 tracks/swift/exercises/binary/Sources/BinaryExample.swift
trackler-2.2.1.177 tracks/swift/exercises/binary/Sources/BinaryExample.swift
trackler-2.2.1.176 tracks/swift/exercises/binary/Sources/BinaryExample.swift
trackler-2.2.1.175 tracks/swift/exercises/binary/Sources/BinaryExample.swift
trackler-2.2.1.174 tracks/swift/exercises/binary/Sources/BinaryExample.swift
trackler-2.2.1.173 tracks/swift/exercises/binary/Sources/BinaryExample.swift
trackler-2.2.1.172 tracks/swift/exercises/binary/Sources/BinaryExample.swift
trackler-2.2.1.171 tracks/swift/exercises/binary/Sources/BinaryExample.swift
trackler-2.2.1.170 tracks/swift/exercises/binary/Sources/BinaryExample.swift
trackler-2.2.1.169 tracks/swift/exercises/binary/Sources/BinaryExample.swift
trackler-2.2.1.167 tracks/swift/exercises/binary/Sources/BinaryExample.swift
trackler-2.2.1.166 tracks/swift/exercises/binary/Sources/BinaryExample.swift
trackler-2.2.1.165 tracks/swift/exercises/binary/Sources/BinaryExample.swift
trackler-2.2.1.164 tracks/swift/exercises/binary/Sources/BinaryExample.swift
trackler-2.2.1.163 tracks/swift/exercises/binary/Sources/BinaryExample.swift
trackler-2.2.1.162 tracks/swift/exercises/binary/Sources/BinaryExample.swift
trackler-2.2.1.161 tracks/swift/exercises/binary/Sources/BinaryExample.swift
trackler-2.2.1.160 tracks/swift/exercises/binary/Sources/BinaryExample.swift