How to convert decimal to binary number in C# using method

    using System;
    using System.Text;

    class DecToBin
    {
        static void Main(string[] args)
        {
            long num = int.MaxValue * 2L;
            Console.WriteLine(DecimalToBinary(num)); // 11111111111111111111111111111110
        }

        private static string DecimalToBinary(long num)
        {
            StringBuilder res = new StringBuilder();
            while (num > 0)
            {
                res.Insert(0, num % 2);
                num /= 2;
            }

            return res.ToString();
        }
    }