Sha256: 661a2a86b09b8dd8f7056b5972317ac654a8572edf4f7ac273dab28ee30fcb1b
Contents?: true
Size: 884 Bytes
Versions: 71
Compression:
Stored size: 884 Bytes
Contents
import Darwin extension Int { init(_ value: Octal) { self = value.toDecimal } } struct Octal { private var stringValue = "" fileprivate var toDecimal: Int = 0 private func isValidOctal() -> Bool { return (Int(stringValue) ?? -1) > -1 ? true : false } private func oct2int(_ input: String) -> Int { let orderedInput = Array(input.characters.reversed()) var tempInt: Int = 0 for (inx, each) in orderedInput.enumerated() { let tempCharInt = Int("\(each)") ?? 0 if tempCharInt > 7 {return 0} let tempOctPower = Int(pow(Double(8), Double(inx))) tempInt += tempOctPower * tempCharInt } return tempInt } init( _ sv: String) { self.stringValue = sv if isValidOctal() { self.toDecimal = oct2int(sv) } } }
Version data entries
71 entries across 71 versions & 1 rubygems