Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
15
Task/Bitwise-operations/Swift/bitwise-operations.swift
Normal file
15
Task/Bitwise-operations/Swift/bitwise-operations.swift
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
func bitwise(a: Int, b: Int) {
|
||||
// All bitwise operations (including shifts)
|
||||
// require both operands to be the same type
|
||||
println("a AND b: \(a & b)")
|
||||
println("a OR b: \(a | b)")
|
||||
println("a XOR b: \(a ^ b)")
|
||||
println("NOT a: \(~a)")
|
||||
println("a << b: \(a << b)") // left shift
|
||||
// for right shifts, if the operands are unsigned, Swift performs
|
||||
// a logical shift; if signed, an arithmetic shift.
|
||||
println("a >> b: \(a >> b)") // arithmetic right shift
|
||||
println("a lsr b: \(Int(bitPattern: UInt(bitPattern: a) >> UInt(bitPattern: b)))") // logical right shift
|
||||
}
|
||||
|
||||
bitwise(-15,3)
|
||||
Loading…
Add table
Add a link
Reference in a new issue