Windows PowerShell 101 DVD Question

Ask your PowerShell-related questions, including questions on cmdlet development!
Forum rules
Do not post any licensing information in this forum.

Any code longer than three lines should be added as code using the 'Select Code' dropdown menu or attached as a file.
This topic is 15 years and 11 months old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.
Locked
User avatar
jsclmedave
Posts: 11
Last visit: Tue Jul 22, 2008 5:52 am

Windows PowerShell 101 DVD Question

Post by jsclmedave »

Question is -

Type the comparison that will allow PowerShell to determine if the fourth bit is "turned on" in the value 192.

Answer is -

129 -band 8
8 -band 129


I am at a loss here... If this is indeed correct can someone please explain?
User avatar
jsclmedave
Posts: 11
Last visit: Tue Jul 22, 2008 5:52 am

Windows PowerShell 101 DVD Question

Post by jsclmedave »

Question is -

Type the comparison that will allow PowerShell to determine if the fourth bit is "turned on" in the value 192.

Answer is -

129 -band 8
8 -band 129


I am at a loss here... If this is indeed correct can someone please explain?
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Windows PowerShell 101 DVD Question

Post by jvierra »

Bit 4 has a value of 8 when set.

2 ** (4-1) or 2 two the third power which is 2 * 2 * 2 or 8.

if bit and 8 matces bit by bit with 129 it will be true.

129 = 10000001 ( 128 + 1) or ( bit 8 + bit 1)
8 = 00001000

Does it match at the bit position.

Try 137 -band 8 it will tell you True.

false = 0
true <> 0

Try the following

[bool]0
[bool]1
[bool]-1

[bool](129 -band 8)
[bool](137 -band 8)
[bool](8 -band 8)

Now are you a believer?
User avatar
jsclmedave
Posts: 11
Last visit: Tue Jul 22, 2008 5:52 am

Windows PowerShell 101 DVD Question

Post by jsclmedave »

Where does the 129 come in? They are all false which I get. The 4th BIT which is 8 in not true.

PS Z:> [bool]0FalsePS Z:> [bool]1TruePS Z:> [bool]-1TruePS Z:> [bool](129 -band 8)FalsePS Z:> [bool](137 -band 8)TruePS Z:> [bool](8 -band 8)TruePS Z:> [bool](8 -band 129)FalsePS Z:> [bool](8 -band 192)FalsePS Z:> [bool](192 -band 8)FalsePS Z:>

So shouldnt the answer to this question be - ?

192 -band 8
8 -band 192


It looks like a typo... If not I am completely lost as to where the 129 came from...
User avatar
donj
Posts: 416
Last visit: Thu May 29, 2008 5:08 am

Windows PowerShell 101 DVD Question

Post by donj »

Sorry, "192." Misread the question. But yes, the correct answer should be

8 -band 192

or

192 -band 8

If it isn't accepting that, then there may be a typo in the quiz module. It's also possible there's an extra or missing space; the quiz module is unfortunately extremely picky about that kind of thing.
User avatar
jsclmedave
Posts: 11
Last visit: Tue Jul 22, 2008 5:52 am

Windows PowerShell 101 DVD Question

Post by jsclmedave »

Thank you all for the clarification and detailed information! Don - The module states the correct answer is - 129 -band 88 -band 129

So yes, I believe it
This topic is 15 years and 11 months old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.
Locked