Bài tập minh họa về toán tử dịch bit trong C-Sharp. (Program to Illustrate LeftShift Operations in C-Sharp.)

Bài tập này minh họa về toán tử LeftShift (<<) tạm dịch là phép toán dịch bit trong ngôn ngữ lập trình C-Sharp.

Left Shift Example


C-Sharp Source Example:
-------------------------------------
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace CSharpExample
{
    class LeftShiftexample
    {

        static void Main(string[] args)
        {

            int x = 1024 * 1024 * 1024;
            uint p = 1024 * 1024 * 1024;
            int y = -42;

            Console.WriteLine("LEFT SHIFT OPERATIONS :");
            Console.WriteLine("{0},{1},{2}", x, x * 2, x << 1);
            Console.WriteLine("{0},{1},{2}", p, p * 2, p << 1);
            Console.WriteLine("{0},{1},{2}", x, x * 4, x << 2);
            Console.WriteLine("{0},{1},{2}", p, p * 4, p << 2);
            Console.WriteLine("{0},{1},{2}", y, y * 1024 * 1024 * 64, x << 26);

            Console.ReadLine();

        }

    }

}
-----------------------------------









No comments:

Post a Comment