Advertisement
Larme

Untitled

Sep 28th, 2021
1,549
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Swift 0.56 KB | None | 0 0
  1. extension Int {
  2.     //Taken from https://stackoverflow.com/a/26181323/1801544
  3.     func pad(toSize: Int) -> String {
  4.         let string = String(self, radix: 2)
  5.         var padded = string
  6.         for _ in 0..<(toSize - string.count) {
  7.             padded = "0" + padded
  8.         }
  9.         return padded
  10.     }
  11. }
  12. func xor() {
  13.     for x in 0...100 {
  14.         let output = x^2
  15.         print("x: \(x.pad(toSize: 8)) - \(x)")
  16.         print("2: \(2.pad(toSize: 8)) - \(2)")
  17.         print("r: \(output.pad(toSize: 8)) - \(output)")
  18.         print("-")
  19.     }
  20. }
  21. xor()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement