Closed servbot007 closed 3 months ago
The code statement:
WriteLine("{0,12} {1,34}", "Decimal", "Binary");
Outputs the headers for the table:
Decimal Binary
The statement:
WriteLine("{0,12} {0,34:B32}", int.MaxValue);
Note that both interpolated values are for argument 0 i.e.
{0,12}
and{0,34:B32}
so you don't need to pass the argument in twice. I suspect this is what you're missing.
Outputs the first row for the maximum value only in both decimal notation and binary notation:
2147483647 01111111111111111111111111111111
The loop:
for (int i = 8; i >= -8; i--)
{
WriteLine("{0,12} {0,34:B32}", i);
}
Outputs the values between 8 and -8 in both decimal notation and binary notation:
8 00000000000000000000000000001000
7 00000000000000000000000000000111
6 00000000000000000000000000000110
5 00000000000000000000000000000101
4 00000000000000000000000000000100
3 00000000000000000000000000000011
2 00000000000000000000000000000010
1 00000000000000000000000000000001
0 00000000000000000000000000000000
-1 11111111111111111111111111111111
-2 11111111111111111111111111111110
-3 11111111111111111111111111111101
-4 11111111111111111111111111111100
-5 11111111111111111111111111111011
-6 11111111111111111111111111111010
-7 11111111111111111111111111111001
-8 11111111111111111111111111111000
And the final statement:
WriteLine("{0,12} {0,34:B32}", int.MinValue);
Outputs the minimum value in both decimal notation and binary notation:
-2147483648 10000000000000000000000000000000
I've created an improvement item for this: https://github.com/markjprice/cs12dotnet8/blob/main/docs/errata/improvements.md#page-99---custom-number-formatting
I do stand corrected. I subconsciously typed this code as {0} and {1}. I went back into the book and see {0} referenced in both places.
Thank you for getting back to me and helping me see this.
Cheers!
Get Outlook for iOShttps://aka.ms/o0ukef
From: Mark J. Price @.> Sent: Saturday, May 11, 2024 6:34:53 AM To: markjprice/cs12dotnet8 @.> Cc: servbot007 @.>; Author @.> Subject: Re: [markjprice/cs12dotnet8] CS 12 .Net 8 page 148 (Issue #37)
I've created an improvement item for this: https://github.com/markjprice/cs12dotnet8/blob/main/docs/errata/improvements.md#page-99---custom-number-formatting
— Reply to this email directly, view it on GitHubhttps://github.com/markjprice/cs12dotnet8/issues/37#issuecomment-2105687627, or unsubscribehttps://github.com/notifications/unsubscribe-auth/AGW673VOKD6QIQXQ2MY2OMLZBX653AVCNFSM6AAAAABHRKM6RGVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDCMBVGY4DONRSG4. You are receiving this because you authored the thread.Message ID: @.***>
In the section "How negative numbers are represented in binary", the last three WriteLine statements are missing the extra int.MaxValue, i, and int.MinValue respectively in their argument lists.
Easy fix but noticed this wasn't on the errata page.