Bill Melius
Bill Melius

Reputation: 1053

Convert C bitwise statement to vb.net

I have a open source project I downloaded to help me through a byte array. I need to convert

int x = fgetc(inpFile);
x |= fgetc(inputfile) <<8;
x |= fgetc(inputfile) <<16;
x |= fgetc(inputfile) <<24;

to vb.net. The fgetc and inpFile I understand. Unfortunately I don't know C++ and I am thin on bitwise operations.

The file format I am trying to interpret (I'm working on an embroidery format reader) is poorly documented, and instructs me that "Address HEX 0008 to 0010 = 3 Bytes pointing to beginning of .... next block of byte array ... "

I'm simply trying to calculate the same value from these three bytes that the example code above does.

Hope this makes sense

Upvotes: 2

Views: 146

Answers (2)

Esailija
Esailija

Reputation: 140230

You could go with BinaryReader, that automatically reads in Little Endian.

Dim reader As BinaryReader
Dim x As Integer

reader = New BinaryReader(File.Open(fileName, FileMode.Open))
x = reader.ReadInt32()

Upvotes: 1

Fredou
Fredou

Reputation: 20120

i will go with this

 dim x as integer = fgetc(inpFile) or 
                    fgetc(inpFile) << 8 or 
                    fgetc(inpFile) << 16 or 
                    fgetc(inpFile) <<24

Upvotes: 3

Related Questions