using System; using System.Text; public class Test { public static void Main() { ushort server_port = 25566; byte[] bytes = new byte[] { (byte) (server_port >> 8), (byte) server_port }; StringBuilder hex = new StringBuilder(bytes.Length * 2); foreach (byte b in bytes) { hex.AppendFormat("{0:x2}", b); } Console.Write(hex); } }