User Tools

Site Tools


Action disabled: source
blog:2025-07-02-001



2025-07-02 C#: BitConverter.ToInt16

  • using System;
    
    public class HelloWorld
    {
        public static void Main(string[] args)
        {
            byte[] gByteAry = new byte[8] {1,2,3,4,5,6,7,8};
            Int16 a, b, c, d;
    
            a = BitConverter.ToInt16(gByteAry, 6);  // wordees(0)
            b = BitConverter.ToInt16(gByteAry, 4);  // wordees(0)
            c = BitConverter.ToInt16(gByteAry, 2);  // wordees(0)
            d = BitConverter.ToInt16(gByteAry, 0);  // wordees(0)
    
            Console.WriteLine ("a = " + a.ToString("X4"));
            Console.WriteLine ("b = " + b.ToString("X4"));
            Console.WriteLine ("c = " + c.ToString("X4"));
            Console.WriteLine ("d = " + d.ToString("X4"));
        }
    }

Execution Output

  • a = 0807
    b = 0605
    c = 0403
    d = 0201

TAGS

  • 2 person(s) visited this page until now.

blog/2025-07-02-001.txt · Last modified: 2025/07/02 09:59 by jethro