Пример #1
0
        // get the character descriptor string
        private static string getCharacterDescName(string name, OutputConfiguration.DescriptorFormat descFormat)
        {
            // create result string
            const string format = "[Char {0} in {1}], ";

            switch (descFormat)
            {
            case OutputConfiguration.DescriptorFormat.DontDisplay:
                // don't display
                return("");

            case OutputConfiguration.DescriptorFormat.DisplayInBits:
                // set value
                return(String.Format(format, name, "bits"));

            case OutputConfiguration.DescriptorFormat.DisplayInBytes:
                // set value
                return(String.Format(format, name, "bytes"));

            default:
                throw new NotImplementedException();
            }
        }
Пример #2
0
        // convert bits to bytes according to desc format
        public static int ConvertValueByDescriptorFormat(OutputConfiguration.DescriptorFormat descFormat, int valueInBits)
        {
            // according to format
            switch (descFormat)
            {
            case OutputConfiguration.DescriptorFormat.DisplayInBytes:
                // get value in bytes
                int valueInBytes = valueInBits / 8;
                if (valueInBits % 8 != 0)
                {
                    valueInBytes++;
                }
                // set into string
                return(valueInBytes);

            case OutputConfiguration.DescriptorFormat.DisplayInBits:
            case OutputConfiguration.DescriptorFormat.DontDisplay:
                // no conversion required
                return(valueInBits);

            default:
                throw new NotImplementedException();
            }
        }