using System;
using System.Collections.Generic;
using System.Text;

namespace isbextract {
    public static class Utils {

        # region Private Variables
        private static char[] m_hexTable = {
            '0', '1', '2', '3', '4', '5', '6', '7',
            '8', '9', 'A', 'B', 'C', 'D', 'E', 'F'
        };
        #endregion

        #region Public Methods

        /// <summary>
        /// Convert byte to String - with padding zero.
        /// </summary>
        /// <param name="b">byte</param>
        /// <returns>hex string</returns>
        public static string ByteToHexString(byte b) {
            return new string(new char[2] { m_hexTable[b >> 4], m_hexTable[b & 0x0F] });
        }

        /// <summary> Converts an array of bytes into a formatted string of hex digits (ex: E4 CA B2)</summary>
        /// <param name="data"> The array of bytes to be translated into a string of hex digits. </param>
        /// <returns> Returns a well formatted string of hex digits. </returns>
        public static string ByteArrayToHexString(byte[] data) {
            if (data != null) {
                string returnValue = "";
                foreach (byte b in data) returnValue += ByteToHexString(b);
                return returnValue;
            }
            return "";
        }
        #endregion
    }
}
