C# to Xojo

Hi,

have those three functions and need help to convert them from C# to Xojo. I’m not sure, if the Bitwise class is the right direction. Can someone help please?

private static int GetInt16(Stream stream) {
  return stream.ReadByte() << 8 | stream.ReadByte();
}

private static int GetInt24(Stream stream) {
  return stream.ReadByte() << 16 |
         stream.ReadByte() << 8 | stream.ReadByte();
}

private static int GetInt32(Stream stream) {
  return stream.ReadByte() << 24 | stream.ReadByte() << 16 |
         stream.ReadByte() << 8 | stream.ReadByte();
}

Yes you could use bit wise shifts
Or an MB like
I believe that in C# int = Int32

GetInt16(stream as BinaryStream) as int32
  var mb as new Memoryblock(2)
  mb.Uint8Value(0) = stream.ReadUint8
  mb.Uint8Value(1) = stream.ReadUint8
  return mb.Uint16Value(0)
}

GetInt24(stream as BinaryStream) as Int32
  var mb as new Memoryblock(3)
  mb.Uint8Value(0) = stream.ReadUint8
  mb.Uint8Value(1) = stream.ReadUint8
  mb.Uint8Value(2) = stream.ReadUint8
   // have to returna uint32
  return mb.Uint32Value(0)
}

private static int GetInt32(Stream stream) {
  var mb as new Memoryblock(4)
  mb.Uint8Value(0) = stream.ReadUint8
  mb.Uint8Value(1) = stream.ReadUint8
  mb.Uint8Value(2) = stream.ReadUint8
  mb.Uint8Value(3) = stream.ReadUint8
   // have to returna uint32
  return mb.Uint32Value(0)
}
1 Like

Thanks, I’ll look into it. Next question, how can we add this as a class property: internal int[][] files;? files() As Pair maybe?

out of context its hard to know what the right thing would be