Operators.swift 858 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  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. */
  19. import Foundation
  20. infix operator &<<= {
  21. associativity none
  22. precedence 160
  23. }
  24. infix operator &<< {
  25. associativity none
  26. precedence 160
  27. }
  28. infix operator &>>= {
  29. associativity none
  30. precedence 160
  31. }
  32. infix operator &>> {
  33. associativity none
  34. precedence 160
  35. }