Operators.swift 839 B

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