I am looking for a way to convert a fractional decimal to binary fraction in Swift 3. But unfortunately Xcode shows error message
"Cannot assign value of type 'Double' to type 'Int'" // line 8
"Binary operator '*' cannot be applied to operands of type 'Double' // line 9
and
'Int'" and "Cannot assign value of type 'Int' to type 'Double'" // line 11
Code itself:
var fraDecimal: Double, fraBinary: Double, bFractional: Double = 0.0, dFractional: Double = 0.6817, fraFactor: Double = 0.1
var dIntegral: Int, bIntegral: Int = 0
var intFactor: Int = 1, remainder: Int, temp: Int, i: Int
var signs: Int = 6
while (signs > 0 && dFractional > 0){
dFractional = dFractional * 2
temp = dFractional
bFractional = bFractional + fraFactor * temp
if(temp == 1) {
dFractional = Int(dFractional) - temp
}
fraFactor=fraFactor/10
signs-=1
}
Maybe there's some kind of workaround?
Thank you for your attention to my request