Convert Byte Array to Integer in Delphi

delphi

Solution

You could declare a Word/Smallint at the same memory location, like this:

var
  b : B02;
  myInt: smallint absolute B02;

Then again, is there any particular reason why you don't just create the smallint and pass it to ReadBuffer instead of an array? I don't know exactly what class you're using, but that looks a lot like the way you read from a TStream, and it'll accept variables of any type, along with a size in bytes. Why not just declare your buffer as the integer type you're looking for and cut out the middleman?

Problem

type B02 = array [01..02] of byte ; ... var b : B02; ... //here i read from tcp socket socket.ReadBuffer(b, 2); The question is: how to convert B02 to an integer?

Original source