shift.carbon 753 B

1234567891011121314151617181920212223242526272829303132
  1. // Part of the Carbon Language project, under the Apache License v2.0 with LLVM
  2. // Exceptions. See /LICENSE for license information.
  3. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  4. //
  5. // AUTOUPDATE
  6. package ExplorerTest api;
  7. fn Main() -> i32 {
  8. if (1 << 0 != 1) { return 1; }
  9. if (1 << 3 != 8) { return 2; }
  10. if (0 << 3 != 0) { return 3; }
  11. if (3 << 1 != 6) { return 4; }
  12. if (-1 << 2 != -4) { return 5; }
  13. if (1 >> 0 != 1) { return 6; }
  14. if (1 >> 1 != 0) { return 7; }
  15. if (3 >> 1 != 1) { return 8; }
  16. if (-1 >> 1 != -1) { return 9; }
  17. if (-2 >> 1 != -1) { return 10; }
  18. var n: i32 = 1;
  19. n <<= 3;
  20. Print("{0}", n);
  21. n >>= 1;
  22. Print("{0}", n);
  23. return 0;
  24. }
  25. // CHECK:STDOUT: 8
  26. // CHECK:STDOUT: 4
  27. // CHECK:STDOUT: result: 0