shift.carbon 752 B

12345678910111213141516171819202122232425262728293031
  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. // CHECK:STDOUT: 8
  7. // CHECK:STDOUT: 4
  8. // CHECK:STDOUT: result: 0
  9. package ExplorerTest api;
  10. fn Main() -> i32 {
  11. if (1 << 0 != 1) { return 1; }
  12. if (1 << 3 != 8) { return 2; }
  13. if (0 << 3 != 0) { return 3; }
  14. if (3 << 1 != 6) { return 4; }
  15. if (-1 << 2 != -4) { return 5; }
  16. if (1 >> 0 != 1) { return 6; }
  17. if (1 >> 1 != 0) { return 7; }
  18. if (3 >> 1 != 1) { return 8; }
  19. if (-1 >> 1 != -1) { return 9; }
  20. if (-2 >> 1 != -1) { return 10; }
  21. var n: i32 = 1;
  22. n <<= 3;
  23. Print("{0}", n);
  24. n >>= 1;
  25. Print("{0}", n);
  26. return 0;
  27. }