Operators.swift 785 B

12345678910111213141516171819202122232425262728
  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 &<<= : BitwiseShiftPrecedence
  20. infix operator &<< : BitwiseShiftPrecedence
  21. infix operator &>>= : BitwiseShiftPrecedence
  22. infix operator &>> : BitwiseShiftPrecedence