byte[] to int

  • Thread starter Thread starter J M
  • Start date Start date
J

J M

How do i convert following fixed byte array:

byte[] b = new byte[]{ 00, 00, 00, 09}
to integer 9????

I tring BitConverter.ToInt16(b, 0) but does not work

Also I tried following but does not work:

byte[] c = new byte[] { 00, 64}

I am not able to get 100 as output.

TIA!
 
using System;

public class ToInt32 {
private static void Main(string[] args) {
byte[] b = new byte[] { 9, 0, 0, 0 };
Console.WriteLine(BitConverter.ToInt32(b,0));
}
}

Reverse the order. If you are looking to use hex chars, then:

byte[] b = new byte[] {0x9, 0x0, 0x0, 0x0};
byte[] b = new byte[] {0x64, 0x0, 0x0, 0x0};
 
Back
Top