Skip to content

Instantly share code, notes, and snippets.

@camiloibarrayepes
Created September 1, 2019 04:01
Show Gist options
  • Select an option

  • Save camiloibarrayepes/5986450d6918657ec5d96f2446eced93 to your computer and use it in GitHub Desktop.

Select an option

Save camiloibarrayepes/5986450d6918657ec5d96f2446eced93 to your computer and use it in GitHub Desktop.
//decimal
let decimalNumber = 17
//Binario
let decimalBinario = 0b10001 // 16*1 + 8*0 + 4*0 + 2*2 + 1*1 + = 17 Binario
//Octal
let decimalOctal = 0o21 //8*2 + 1*1
//hexadecimal
let decimalHexa = 0x11 //16*1+1
let number = 1.25e2 //1.25*10^2
let numberTwo = 1.25e-2 //0.0125
let numberThree = 0xFp2 // 15*2^2
let numberFour = 0xFp-2 // 15*2^-2
//Casting y conversiones numéricas
//Int8: -128 a 127
//Uint: 0 a 255
//Ejemplo Casting
let twoThousand: UInt16 = 2_000
let one: UInt8 = 1
//let twoThousandOne = twoThousand + one //Error
let twoThousandOne = twoThousand + UInt16(one)
//TypeAlias
typealias AudioSample = UInt16
var maxAmplitud = AudioSample.max //numero maximo en UInt16, se renombró UInt16 por AudioSample
var mySample : [AudioSample] = [0,6,32,35,57]
//Tuplas
let httpError : (Int, String) = [404, "Error not found"]
let coordinates : (Int, Int, Int)
let password : (String, Bool)
let (statusCode, statusMessage) = httpError
print("El codigo de error es \(statusCode) y el mensaje es \(statusMessage)")
let (statusCode, _) = httpError
print("el codigo es \(statusCode)")
print("La primera parte es \(httpError.0) y la segunda \(httpError.1)")
let http200Status = (statusCode: 200, description: "OK")
print(http200Status.statusCode)
print(http200Status.description)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment