vexx32 / PSKoans

A simple, fun, and interactive way to learn the PowerShell language through Pester unit testing.
GNU General Public License v3.0
1.73k stars 176 forks source link

AboutBitwiseOperations - Error in description? #466

Open DEberhardt opened 2 years ago

DEberhardt commented 2 years ago

Describe "Koan Bug, Issue, or Help Request"

AboutBitwiseOperations

Context "The Problematic Assertions"

The following two statements seem to contradict themselves (it is late here and I am studying, so I will revisit this in the morning again, but I think we have an error in description for LEAST/MOST:

        It 'A byte is made up of 8 bits' {
            <#
                Each bit can be set to either 0 or and each has a value based
                on its position.

                The most significant bit, the largest value, is first. The least
                significant bit, the smallest value, is last.

                    Bit position      Value
                    ------------      -----
                               1        128
                               2         64
                               3         32
                               4         16
                               5          8
                               6          4
                               7          2
                               8          1

                This order is known as Big Endian.
            #>

            '00000001' | ConvertFrom-Binary | Should -Be 1      # Least significant
            '00000010' | ConvertFrom-Binary | Should -Be 2
            '00000100' | ConvertFrom-Binary | Should -Be 4
            '00001000' | ConvertFrom-Binary | Should -Be 8
            '00010000' | ConvertFrom-Binary | Should -Be 16
            '00100000' | ConvertFrom-Binary | Should -Be 32
            '01000000' | ConvertFrom-Binary | Should -Be 64
            '10000000' | ConvertFrom-Binary | Should -Be 128    # Most significant
        }

and

        It 'a binary string can be used to represent different numeric values' {
            # The number it represents can depend on the numeric type used.

            $BinaryValue = '11100001'

            $BinaryValue | ConvertFrom-Binary -To Byte | Should -Be 225
            $BinaryValue | ConvertFrom-Binary -To SByte | Should -Be -31

            <#
                As the signing bit is always the least significant, converting the 8 bit
                binary value above to a larger type, such as, Int32 will create a positive value.
            #>

            $BinaryValue | ConvertFrom-Binary -To Int32 | Should -Be 225
        }

I think this should read As the signing bit is always the most significant...

Context "Your Attempts"

an attempt at understanding late at night.

Context "Additional Information"

the moon illuminates a path

indented-automation commented 2 years ago

Huh, yes... will fix. Thanks!