Operators.swift 770 B

123456789101112131415161718192021222324
  1. //
  2. // Operators.swift
  3. // CryptoSwift
  4. //
  5. // Created by Marcin Krzyzanowski on 02/09/14.
  6. // Copyright (c) 2014 Marcin Krzyzanowski. All rights reserved.
  7. //
  8. /*
  9. Bit shifting with overflow protection using overflow operator "&".
  10. Approach is consistent with standard overflow operators &+, &-, &*, &/
  11. and introduce new overflow operators for shifting: &<<, &>>
  12. Note: Works with unsigned integers values only
  13. Usage
  14. var i = 1 // init
  15. var j = i &<< 2 //shift left
  16. j &<<= 2 //shift left and assign
  17. @see: https://medium.com/@krzyzanowskim/swiftly-shift-bits-and-protect-yourself-be33016ce071
  18. This fuctonality is now implemented as part of Swift 3, SE-0104 https://github.com/apple/swift-evolution/blob/master/proposals/0104-improved-integers.md
  19. */