Int2 Binary Algorithm

They let fast lookup, addition and removal of items, and can be used to implement either dynamic sets of items, or lookup tables that let finding an item by its key (e.g., finding the telephone number of a person by name).Binary search trees keep their keys in sorted order, so that lookup and other operations can use the principle of binary search: when looking for a key in a tree (or a place to insert a new key), they traverse the tree from root to leaf, make comparisons to keys stored in the nodes of the tree and deciding, on the basis of the comparison, to continue searching in the left or right subtrees.
namespace Algorithms.Other
{
    /// <summary>
    /// Manually converts an integer of certain size to a string of the binary representation.
    /// </summary>
    public static class Int2Binary
    {
        /// <summary>
        /// Returns string of the binary representation of given Int.
        /// </summary>
        /// <param name="input">Number to be converted.</param>
        /// <returns>Binary representation of input.</returns>
        public static string Int2Bin(ushort input)
        {
            ushort msb = ushort.MaxValue / 2 + 1;
            var output = string.Empty;
            for (var i = 0; i < 16; i++)
            {
                if (input >= msb)
                {
                    output += "1";
                    input -= msb;
                    msb /= 2;
                }
                else
                {
                    output += "0";
                    msb /= 2;
                }
            }

            return output;
        }

        /// <summary>
        /// Returns string of the binary representation of given Int.
        /// </summary>
        /// <param name="input">Number to be converted.</param>
        /// <returns>Binary representation of input.</returns>
        public static string Int2Bin(uint input)
        {
            var msb = uint.MaxValue / 2 + 1;
            var output = string.Empty;
            for (var i = 0; i < 32; i++)
            {
                if (input >= msb)
                {
                    output += "1";
                    input -= msb;
                    msb /= 2;
                }
                else
                {
                    output += "0";
                    msb /= 2;
                }
            }

            return output;
        }

        /// <summary>
        /// Returns string of the binary representation of given Int.
        /// </summary>
        /// <param name="input">Number to be converted.</param>
        /// <returns>Binary representation of input.</returns>
        public static string Int2Bin(ulong input)
        {
            var msb = ulong.MaxValue / 2 + 1;
            var output = string.Empty;
            for (var i = 0; i < 64; i++)
            {
                if (input >= msb)
                {
                    output += "1";
                    input -= msb;
                    msb /= 2;
                }
                else
                {
                    output += "0";
                    msb /= 2;
                }
            }

            return output;
        }
    }
}

LANGUAGE:

DARK MODE: