Sha256: 56eeb47d1a1cf5599c432a2e984e52e83d569ac7b7929fea55d90a1369fb839c

Contents?: true

Size: 858 Bytes

Versions: 30

Compression:

Stored size: 858 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 {get {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

30 entries across 30 versions & 1 rubygems

Version Path
trackler-2.0.3.4 tracks/swift/exercises/binary/BinaryExample.swift
trackler-2.0.3.3 tracks/swift/exercises/binary/BinaryExample.swift
trackler-2.0.3.2 tracks/swift/exercises/binary/BinaryExample.swift
trackler-2.0.3.1 tracks/swift/exercises/binary/BinaryExample.swift
trackler-2.0.3.0 tracks/swift/exercises/binary/BinaryExample.swift
trackler-2.0.2.0 tracks/swift/exercises/binary/BinaryExample.swift
trackler-2.0.1.2 tracks/swift/exercises/binary/BinaryExample.swift
trackler-2.0.1.1 tracks/swift/exercises/binary/BinaryExample.swift
trackler-2.0.1.0 tracks/swift/exercises/binary/BinaryExample.swift
trackler-2.0.0.10 tracks/swift/exercises/binary/BinaryExample.swift
trackler-2.0.0.9 tracks/swift/exercises/binary/BinaryExample.swift
trackler-2.0.0.8 tracks/swift/exercises/binary/BinaryExample.swift
trackler-2.0.0.7 tracks/swift/exercises/binary/BinaryExample.swift
trackler-2.0.0.6 tracks/swift/exercises/binary/BinaryExample.swift
trackler-2.0.0.5 tracks/swift/exercises/binary/BinaryExample.swift
trackler-2.0.0.4 tracks/swift/exercises/binary/BinaryExample.swift
trackler-2.0.0.3 tracks/swift/exercises/binary/BinaryExample.swift
trackler-2.0.0.2 tracks/swift/exercises/binary/BinaryExample.swift
trackler-2.0.0.1 tracks/swift/exercises/binary/BinaryExample.swift
trackler-2.0.0.0 tracks/swift/exercises/binary/BinaryExample.swift