.binaryBitPattern

๐Ÿ’พ ็จ‹ๅผ๏ผšreplit

extension BinaryFloatingPoint {

    /// `num.signBitPattern`
    public var signBitPattern: String {
        return sign == .plus ? "0" : "1"
    }

    /// `num.binaryBitPattern`
    public var binaryBitPattern: String {
        return signBitPattern 
            + String(exponentBitPattern, radix: 2)
            + String(significandBitPattern, radix: 2)
    }
}

๐Ÿ’ˆ็ฏ„ไพ‹๏ผš

let x = Double.pi
x.binaryBitPattern
//  โ•ญโ”€โ”€ exp โ”€โ”€โ•ฎโ•ญโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€ significand โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ•ฎ
// 0100000000001001001000011111101101010100010001000010110100011000
// โ†ณ sign

Last updated