Skip to content

Commit 73a90a3

Browse files
authored
Fixes #10312 - Update shift-right for negative numbers (#10320)
* Update shift-right for negative numbers * fix transposed values in table
1 parent 5fbba98 commit 73a90a3

File tree

4 files changed

+80
-120
lines changed

4 files changed

+80
-120
lines changed

reference/5.1/Microsoft.PowerShell.Core/About/about_Arithmetic_Operators.md

Lines changed: 20 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
description: Describes the operators that perform arithmetic in PowerShell.
33
Locale: en-US
4-
ms.date: 08/29/2022
4+
ms.date: 08/01/2023
55
online version: https://learn.microsoft.com/powershell/module/microsoft.powershell.core/about/about_arithmetic_operators?view=powershell-5.1&WT.mc_id=ps-gethelp
66
schema: 2.0.0
77
title: about Arithmetic Operators
@@ -542,42 +542,32 @@ In a bitwise shift-left operation, all bits are moved "n" places to the left,
542542
where "n" is the value of the right operand. A zero is inserted in the ones
543543
place.
544544

545-
When the left operand is an Integer (32-bit) value, the lower 5 bits of the
546-
right operand determine how many bits of the left operand are shifted.
547-
548-
When the left operand is a Long (64-bit) value, the lower 6 bits of the right
549-
operand determine how many bits of the left operand are shifted.
550-
551545
| Expression | Result | Binary Result |
552546
| ----------- | ------ | ------------- |
553547
| `21 -shl 0` | 21 | 0001 0101 |
554548
| `21 -shl 1` | 42 | 0010 1010 |
555549
| `21 -shl 2` | 84 | 0101 0100 |
556550

557551
In a bitwise shift-right operation, all bits are moved "n" places to the right,
558-
where "n" is specified by the right operand. The shift-right operator (-shr)
559-
inserts a zero in the left-most place when shifting a positive or unsigned
560-
value to the right.
561-
562-
When the left operand is an Integer (32-bit) value, the lower 5 bits of the
563-
right operand determine how many bits of the left operand are shifted.
564-
565-
When the left operand is a Long (64-bit) value, the lower 6 bits of the right
566-
operand determine how many bits of the left operand are shifted.
567-
568-
| Expression | Result | Binary | Hex |
569-
| ------------------------ | ----------- | --------- | ---------- |
570-
| `21 -shr 0` | 21 | 0001 0101 | 0x15 |
571-
| `21 -shr 1` | 10 | 0000 1010 | 0x0A |
572-
| `21 -shr 2` | 5 | 0000 0101 | 0x05 |
573-
| `21 -shr 31` | 0 | 0000 0000 | 0x00 |
574-
| `21 -shr 32` | 21 | 0001 0101 | 0x15 |
575-
| `21 -shr 64` | 21 | 0001 0101 | 0x15 |
576-
| `21 -shr 65` | 10 | 0000 1010 | 0x0A |
577-
| `21 -shr 66` | 5 | 0000 0101 | 0x05 |
578-
| `[int]::MaxValue -shr 1` | 1073741823 | | 0x3FFFFFFF |
579-
| `[int]::MinValue -shr 1` | -1073741824 | | 0xC0000000 |
580-
| `-1 -shr 1` | -1 | | 0xFFFFFFFF |
552+
where "n" is specified by the right operand. The shift-right operator (`-shr`)
553+
copies the sign bit to the left-most place when shifting a signed value. For
554+
unsigned values, a zero is inserted in the left-most position.
555+
556+
| Expression | Result | Binary | Hex |
557+
| :----------------------: | ----------: | -------------------------------: | ---------: |
558+
| `21 -shr 0` | 21 | 00010101 | 0x15 |
559+
| `21 -shr 1` | 10 | 00001010 | 0x0A |
560+
| `21 -shr 2` | 5 | 00000101 | 0x05 |
561+
| `21 -shr 31` | 0 | 00000000 | 0x00 |
562+
| `21 -shr 32` | 21 | 00010101 | 0x15 |
563+
| `21 -shr 64` | 21 | 00010101 | 0x15 |
564+
| `21 -shr 65` | 10 | 00001010 | 0x0A |
565+
| `21 -shr 66` | 5 | 00000101 | 0x05 |
566+
| `[int]::MaxValue -shr 1` | 1073741823 | 00111111111111111111111111111111 | 0x3FFFFFFF |
567+
| `[int]::MinValue -shr 1` | -1073741824 | 11000000000000000000000000000000 | 0xC0000000 |
568+
| `-1 -shr 1` | -1 | 11111111111111111111111111111111 | 0xFFFFFFFF |
569+
| `(-21 -shr 1)` | -11 | 11111111111111111111111111110101 | 0xFFFFFFF5 |
570+
| `(-21 -shr 2)` | -6 | 11111111111111111111111111111010 | 0xFFFFFFF4 |
581571

582572
## See also
583573

reference/7.2/Microsoft.PowerShell.Core/About/about_Arithmetic_Operators.md

Lines changed: 20 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
description: Describes the operators that perform arithmetic in PowerShell.
33
Locale: en-US
4-
ms.date: 08/29/2022
4+
ms.date: 08/01/2023
55
online version: https://learn.microsoft.com/powershell/module/microsoft.powershell.core/about/about_arithmetic_operators?view=powershell-7.2&WT.mc_id=ps-gethelp
66
schema: 2.0.0
77
title: about Arithmetic Operators
@@ -542,42 +542,32 @@ In a bitwise shift-left operation, all bits are moved "n" places to the left,
542542
where "n" is the value of the right operand. A zero is inserted in the ones
543543
place.
544544

545-
When the left operand is an Integer (32-bit) value, the lower 5 bits of the
546-
right operand determine how many bits of the left operand are shifted.
547-
548-
When the left operand is a Long (64-bit) value, the lower 6 bits of the right
549-
operand determine how many bits of the left operand are shifted.
550-
551545
| Expression | Result | Binary Result |
552546
| ----------- | ------ | ------------- |
553547
| `21 -shl 0` | 21 | 0001 0101 |
554548
| `21 -shl 1` | 42 | 0010 1010 |
555549
| `21 -shl 2` | 84 | 0101 0100 |
556550

557551
In a bitwise shift-right operation, all bits are moved "n" places to the right,
558-
where "n" is specified by the right operand. The shift-right operator (-shr)
559-
inserts a zero in the left-most place when shifting a positive or unsigned
560-
value to the right.
561-
562-
When the left operand is an Integer (32-bit) value, the lower 5 bits of the
563-
right operand determine how many bits of the left operand are shifted.
564-
565-
When the left operand is a Long (64-bit) value, the lower 6 bits of the right
566-
operand determine how many bits of the left operand are shifted.
567-
568-
| Expression | Result | Binary | Hex |
569-
| ------------------------ | ----------- | --------- | ---------- |
570-
| `21 -shr 0` | 21 | 0001 0101 | 0x15 |
571-
| `21 -shr 1` | 10 | 0000 1010 | 0x0A |
572-
| `21 -shr 2` | 5 | 0000 0101 | 0x05 |
573-
| `21 -shr 31` | 0 | 0000 0000 | 0x00 |
574-
| `21 -shr 32` | 21 | 0001 0101 | 0x15 |
575-
| `21 -shr 64` | 21 | 0001 0101 | 0x15 |
576-
| `21 -shr 65` | 10 | 0000 1010 | 0x0A |
577-
| `21 -shr 66` | 5 | 0000 0101 | 0x05 |
578-
| `[int]::MaxValue -shr 1` | 1073741823 | | 0x3FFFFFFF |
579-
| `[int]::MinValue -shr 1` | -1073741824 | | 0xC0000000 |
580-
| `-1 -shr 1` | -1 | | 0xFFFFFFFF |
552+
where "n" is specified by the right operand. The shift-right operator (`-shr`)
553+
copies the sign bit to the left-most place when shifting a signed value. For
554+
unsigned values, a zero is inserted in the left-most position.
555+
556+
| Expression | Result | Binary | Hex |
557+
| :----------------------: | ----------: | -------------------------------: | ---------: |
558+
| `21 -shr 0` | 21 | 00010101 | 0x15 |
559+
| `21 -shr 1` | 10 | 00001010 | 0x0A |
560+
| `21 -shr 2` | 5 | 00000101 | 0x05 |
561+
| `21 -shr 31` | 0 | 00000000 | 0x00 |
562+
| `21 -shr 32` | 21 | 00010101 | 0x15 |
563+
| `21 -shr 64` | 21 | 00010101 | 0x15 |
564+
| `21 -shr 65` | 10 | 00001010 | 0x0A |
565+
| `21 -shr 66` | 5 | 00000101 | 0x05 |
566+
| `[int]::MaxValue -shr 1` | 1073741823 | 00111111111111111111111111111111 | 0x3FFFFFFF |
567+
| `[int]::MinValue -shr 1` | -1073741824 | 11000000000000000000000000000000 | 0xC0000000 |
568+
| `-1 -shr 1` | -1 | 11111111111111111111111111111111 | 0xFFFFFFFF |
569+
| `(-21 -shr 1)` | -11 | 11111111111111111111111111110101 | 0xFFFFFFF5 |
570+
| `(-21 -shr 2)` | -6 | 11111111111111111111111111111010 | 0xFFFFFFF4 |
581571

582572
## See also
583573

reference/7.3/Microsoft.PowerShell.Core/About/about_Arithmetic_Operators.md

Lines changed: 20 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
description: Describes the operators that perform arithmetic in PowerShell.
33
Locale: en-US
4-
ms.date: 08/29/2022
4+
ms.date: 08/01/2023
55
online version: https://learn.microsoft.com/powershell/module/microsoft.powershell.core/about/about_arithmetic_operators?view=powershell-7.3&WT.mc_id=ps-gethelp
66
schema: 2.0.0
77
title: about Arithmetic Operators
@@ -542,42 +542,32 @@ In a bitwise shift-left operation, all bits are moved "n" places to the left,
542542
where "n" is the value of the right operand. A zero is inserted in the ones
543543
place.
544544

545-
When the left operand is an Integer (32-bit) value, the lower 5 bits of the
546-
right operand determine how many bits of the left operand are shifted.
547-
548-
When the left operand is a Long (64-bit) value, the lower 6 bits of the right
549-
operand determine how many bits of the left operand are shifted.
550-
551545
| Expression | Result | Binary Result |
552546
| ----------- | ------ | ------------- |
553547
| `21 -shl 0` | 21 | 0001 0101 |
554548
| `21 -shl 1` | 42 | 0010 1010 |
555549
| `21 -shl 2` | 84 | 0101 0100 |
556550

557551
In a bitwise shift-right operation, all bits are moved "n" places to the right,
558-
where "n" is specified by the right operand. The shift-right operator (-shr)
559-
inserts a zero in the left-most place when shifting a positive or unsigned
560-
value to the right.
561-
562-
When the left operand is an Integer (32-bit) value, the lower 5 bits of the
563-
right operand determine how many bits of the left operand are shifted.
564-
565-
When the left operand is a Long (64-bit) value, the lower 6 bits of the right
566-
operand determine how many bits of the left operand are shifted.
567-
568-
| Expression | Result | Binary | Hex |
569-
| ------------------------ | ----------- | --------- | ---------- |
570-
| `21 -shr 0` | 21 | 0001 0101 | 0x15 |
571-
| `21 -shr 1` | 10 | 0000 1010 | 0x0A |
572-
| `21 -shr 2` | 5 | 0000 0101 | 0x05 |
573-
| `21 -shr 31` | 0 | 0000 0000 | 0x00 |
574-
| `21 -shr 32` | 21 | 0001 0101 | 0x15 |
575-
| `21 -shr 64` | 21 | 0001 0101 | 0x15 |
576-
| `21 -shr 65` | 10 | 0000 1010 | 0x0A |
577-
| `21 -shr 66` | 5 | 0000 0101 | 0x05 |
578-
| `[int]::MaxValue -shr 1` | 1073741823 | | 0x3FFFFFFF |
579-
| `[int]::MinValue -shr 1` | -1073741824 | | 0xC0000000 |
580-
| `-1 -shr 1` | -1 | | 0xFFFFFFFF |
552+
where "n" is specified by the right operand. The shift-right operator (`-shr`)
553+
copies the sign bit to the left-most place when shifting a signed value. For
554+
unsigned values, a zero is inserted in the left-most position.
555+
556+
| Expression | Result | Binary | Hex |
557+
| :----------------------: | ----------: | -------------------------------: | ---------: |
558+
| `21 -shr 0` | 21 | 00010101 | 0x15 |
559+
| `21 -shr 1` | 10 | 00001010 | 0x0A |
560+
| `21 -shr 2` | 5 | 00000101 | 0x05 |
561+
| `21 -shr 31` | 0 | 00000000 | 0x00 |
562+
| `21 -shr 32` | 21 | 00010101 | 0x15 |
563+
| `21 -shr 64` | 21 | 00010101 | 0x15 |
564+
| `21 -shr 65` | 10 | 00001010 | 0x0A |
565+
| `21 -shr 66` | 5 | 00000101 | 0x05 |
566+
| `[int]::MaxValue -shr 1` | 1073741823 | 00111111111111111111111111111111 | 0x3FFFFFFF |
567+
| `[int]::MinValue -shr 1` | -1073741824 | 11000000000000000000000000000000 | 0xC0000000 |
568+
| `-1 -shr 1` | -1 | 11111111111111111111111111111111 | 0xFFFFFFFF |
569+
| `(-21 -shr 1)` | -11 | 11111111111111111111111111110101 | 0xFFFFFFF5 |
570+
| `(-21 -shr 2)` | -6 | 11111111111111111111111111111010 | 0xFFFFFFF4 |
581571

582572
## See also
583573

reference/7.4/Microsoft.PowerShell.Core/About/about_Arithmetic_Operators.md

Lines changed: 20 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
description: Describes the operators that perform arithmetic in PowerShell.
33
Locale: en-US
4-
ms.date: 08/29/2022
4+
ms.date: 08/01/2023
55
online version: https://learn.microsoft.com/powershell/module/microsoft.powershell.core/about/about_arithmetic_operators?view=powershell-7.4&WT.mc_id=ps-gethelp
66
schema: 2.0.0
77
title: about Arithmetic Operators
@@ -542,42 +542,32 @@ In a bitwise shift-left operation, all bits are moved "n" places to the left,
542542
where "n" is the value of the right operand. A zero is inserted in the ones
543543
place.
544544

545-
When the left operand is an Integer (32-bit) value, the lower 5 bits of the
546-
right operand determine how many bits of the left operand are shifted.
547-
548-
When the left operand is a Long (64-bit) value, the lower 6 bits of the right
549-
operand determine how many bits of the left operand are shifted.
550-
551545
| Expression | Result | Binary Result |
552546
| ----------- | ------ | ------------- |
553547
| `21 -shl 0` | 21 | 0001 0101 |
554548
| `21 -shl 1` | 42 | 0010 1010 |
555549
| `21 -shl 2` | 84 | 0101 0100 |
556550

557551
In a bitwise shift-right operation, all bits are moved "n" places to the right,
558-
where "n" is specified by the right operand. The shift-right operator (-shr)
559-
inserts a zero in the left-most place when shifting a positive or unsigned
560-
value to the right.
561-
562-
When the left operand is an Integer (32-bit) value, the lower 5 bits of the
563-
right operand determine how many bits of the left operand are shifted.
564-
565-
When the left operand is a Long (64-bit) value, the lower 6 bits of the right
566-
operand determine how many bits of the left operand are shifted.
567-
568-
| Expression | Result | Binary | Hex |
569-
| ------------------------ | ----------- | --------- | ---------- |
570-
| `21 -shr 0` | 21 | 0001 0101 | 0x15 |
571-
| `21 -shr 1` | 10 | 0000 1010 | 0x0A |
572-
| `21 -shr 2` | 5 | 0000 0101 | 0x05 |
573-
| `21 -shr 31` | 0 | 0000 0000 | 0x00 |
574-
| `21 -shr 32` | 21 | 0001 0101 | 0x15 |
575-
| `21 -shr 64` | 21 | 0001 0101 | 0x15 |
576-
| `21 -shr 65` | 10 | 0000 1010 | 0x0A |
577-
| `21 -shr 66` | 5 | 0000 0101 | 0x05 |
578-
| `[int]::MaxValue -shr 1` | 1073741823 | | 0x3FFFFFFF |
579-
| `[int]::MinValue -shr 1` | -1073741824 | | 0xC0000000 |
580-
| `-1 -shr 1` | -1 | | 0xFFFFFFFF |
552+
where "n" is specified by the right operand. The shift-right operator (`-shr`)
553+
copies the sign bit to the left-most place when shifting a signed value. For
554+
unsigned values, a zero is inserted in the left-most position.
555+
556+
| Expression | Result | Binary | Hex |
557+
| :----------------------: | ----------: | -------------------------------: | ---------: |
558+
| `21 -shr 0` | 21 | 00010101 | 0x15 |
559+
| `21 -shr 1` | 10 | 00001010 | 0x0A |
560+
| `21 -shr 2` | 5 | 00000101 | 0x05 |
561+
| `21 -shr 31` | 0 | 00000000 | 0x00 |
562+
| `21 -shr 32` | 21 | 00010101 | 0x15 |
563+
| `21 -shr 64` | 21 | 00010101 | 0x15 |
564+
| `21 -shr 65` | 10 | 00001010 | 0x0A |
565+
| `21 -shr 66` | 5 | 00000101 | 0x05 |
566+
| `[int]::MaxValue -shr 1` | 1073741823 | 00111111111111111111111111111111 | 0x3FFFFFFF |
567+
| `[int]::MinValue -shr 1` | -1073741824 | 11000000000000000000000000000000 | 0xC0000000 |
568+
| `-1 -shr 1` | -1 | 11111111111111111111111111111111 | 0xFFFFFFFF |
569+
| `(-21 -shr 1)` | -11 | 11111111111111111111111111110101 | 0xFFFFFFF5 |
570+
| `(-21 -shr 2)` | -6 | 11111111111111111111111111111010 | 0xFFFFFFF4 |
581571

582572
## See also
583573

0 commit comments

Comments
 (0)