Binary Reader

N

nick.stefanov

Ok having another issue with binary reader. My file contains values 08
8A . When I read ReadBytes(2) what gets stored in the array is [0] = 8
and [1] = 138. How do I convert that to 2186 integer value?

Thanks
 
S

sarin.rajendran

Not really sure what your requirement is. But if you know that your
file contains an integer value(s), why don't you use the ReadInt32
method?

Regards,
Sarin.
 
A

Abubakar

8A . When I read ReadBytes(2) what gets stored in the array is [0] = 8
and [1] = 138. How do I convert that to 2186 integer value?

You can do the following:

int x=8,y=138;
int answer = (x << 8 ) | y;

answer will have the 2186 value;

hope that helps.

Ab.
http://joehacker.blogspot.com

Ok having another issue with binary reader. My file contains values 08
8A . When I read ReadBytes(2) what gets stored in the array is [0] = 8
and [1] = 138. How do I convert that to 2186 integer value?

Thanks
 
N

nick.stefanov

Yes thanks that works, do you know of a method in c# that automatically
does that? Thanks.

Nick
 
J

Jon Skeet [C# MVP]

Yes thanks that works, do you know of a method in c# that automatically
does that? Thanks.

Yes - see my previous reply. Basically you want BinaryReader or
BitConverter, but big-endian versions - which are two of the things
that my library gives you. (It's free, btw - I should have said
before.)
 
A

Abubakar

Yes thanks that works, do you know of a method in c# that automatically
does that? Thanks.

I'm afraid not. I think you might wanna give a try to Jon's library. I havnt
used it.

btw, sorry for late response, I couldnt access internet for most of saturday
and wont be using it on sunday as well.

Ab.
http://joehacker.blogspot.com
 
N

nick.stefanov

Thanks for your reply. Do you have a link or any instructions on how
to use that library. Thank you very much.

Nick
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top