예제 #1
0
        public static int getOctNumber(string octString, Array dest, int offset, int baseSizeInByte = 4, Boolean isSwap = false)
        {
            if (octString == null || octString.Length == 0)
            {
                return(0);
            }

            if (octString[0].Equals('0'))
            {
                octString = octString.Substring(1);
            }
            Int64 octNum  = getOctNumber(octString);
            int   octSize = getIntBytes(octNum);

            if (octSize > baseSizeInByte)
            {
                baseSizeInByte = octSize;
            }

            if (isSwap)
            {
                NetUsable <byte> .arrayToOtherArraySwappedBySize(
                    BitConverter.GetBytes(octNum), 0, dest, offset, baseSizeInByte, sizeof(Int64));
            }
            else
            {
                Buffer.BlockCopy(BitConverter.GetBytes(octNum), sizeof(Int64) - baseSizeInByte, dest, offset, baseSizeInByte);
            }

            return(baseSizeInByte);
        }
예제 #2
0
        private static int getIntNumber(string num, Array dest, int offset, int baseSizeInByte, Boolean isSwap = false)
        {
            if (num == null || num.Length == 0)
            {
                return(0);
            }
            Int64 tempNum = Int64.Parse(num);

            baseSizeInByte = (getIntBytes(tempNum) > baseSizeInByte) ? getIntBytes(tempNum) : baseSizeInByte;
            Byte[] numArr;

            if (baseSizeInByte == 1)
            {
                numArr = BitConverter.GetBytes((byte)tempNum);
            }
            else if (baseSizeInByte == 2)
            {
                numArr = BitConverter.GetBytes((short)tempNum);
            }
            else if (baseSizeInByte == 4)
            {
                numArr = BitConverter.GetBytes((int)tempNum);
            }
            else
            {
                numArr = BitConverter.GetBytes(tempNum);
            }

            if (isSwap)
            {
                NetUsable <byte> .arrayToOtherArraySwappedBySize(numArr, 0, dest, offset, baseSizeInByte, baseSizeInByte);
            }
            else
            {
                Buffer.BlockCopy(numArr, 0, dest, offset, baseSizeInByte);
            }

            return(baseSizeInByte);
        }