CS 12 .Net 8 page 148
servbot007 opened this issue · 4 comments
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.
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