mirror of
https://github.com/markjprice/cs11dotnet7.git
synced 2026-04-05 14:25:37 +00:00
Initial commit
This commit is contained in:
parent
ca7684985d
commit
49bdd4dda1
60 changed files with 1527 additions and 30 deletions
|
|
@ -0,0 +1,14 @@
|
|||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<OutputType>Exe</OutputType>
|
||||
<TargetFramework>net6.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Using Include="System.Console" Static="true" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
30
vscode/Chapter03/BitwiseAndShiftOperators/Program.cs
Normal file
30
vscode/Chapter03/BitwiseAndShiftOperators/Program.cs
Normal file
|
|
@ -0,0 +1,30 @@
|
|||
int a = 10; // 00001010
|
||||
int b = 6; // 00000110
|
||||
|
||||
WriteLine($"a = {a}");
|
||||
WriteLine($"b = {b}");
|
||||
WriteLine($"a & b = {a & b}"); // 2-bit column only
|
||||
WriteLine($"a | b = {a | b}"); // 8, 4, and 2-bit columns
|
||||
WriteLine($"a ^ b = {a ^ b}"); // 8 and 4-bit columns
|
||||
|
||||
// 01010000 left-shift a by three bit columns
|
||||
WriteLine($"a << 3 = {a << 3}");
|
||||
|
||||
// multiply a by 8
|
||||
WriteLine($"a * 8 = {a * 8}");
|
||||
|
||||
// 00000011 right-shift b by one bit column
|
||||
WriteLine($"b >> 1 = {b >> 1}");
|
||||
|
||||
WriteLine();
|
||||
WriteLine("Outputting integers as binary:");
|
||||
WriteLine($"a = {ToBinaryString(a)}");
|
||||
WriteLine($"b = {ToBinaryString(b)}");
|
||||
WriteLine($"a & b = {ToBinaryString(a & b)}");
|
||||
WriteLine($"a | b = {ToBinaryString(a | b)}");
|
||||
WriteLine($"a ^ b = {ToBinaryString(a ^ b)}");
|
||||
|
||||
static string ToBinaryString(int value)
|
||||
{
|
||||
return Convert.ToString(value, toBase: 2).PadLeft(8, '0');
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue