Bitwise operations: Difference between revisions

added swift
(Updated D entry)
(added swift)
Line 2,385:
print ("a asr b: " ^ Word.fmt StringCvt.DEC (Word.>> (a, b) ) ^ "\n") (* logical right shift *)
)</lang>
 
=={{header|Swift}}==
<lang swift>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: \((a.asUnsigned() >> b.asUnsigned()).asSigned())"); // logical right shift
}</lang>
 
=={{header|SystemVerilog}}==
Anonymous user