Saleh Masum
Saleh Masum

Reputation: 2187

How to perform bitwise or operation between two binary numbers in Swift?

I need to do bitwise OR of two binary strings.

For example, if the binary strings are "110001" and "101101", then I need the result as "111101".

How can I do this in Swift ?

Upvotes: 2

Views: 646

Answers (1)

AchmadJP
AchmadJP

Reputation: 903

You can convert it first into Int

let a = Int("110001", radix: 2)!
let b = Int("101101", radix: 2)!
let c = a | b

let stringResult = String(c, radix: 2, uppercase: false)

More info:

Upvotes: 7

Related Questions