473,513 Members | 2,263 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Binary help please

I'm trying to read some data from a disk file created by a third party
application (written I think in C), so I don't have any option other
than to read/interpret the data in the format in which it's been
saved. There's one particular field giving me problems:

The problematic data item is a 2-byte field saved as an unsigned
integer and has two problems:

1. I know that I can't read a uint directly in to VB.Net (Framework
1.1 at least) as a native type. But presumably there's nothing
stopping me reading it as a short and (?) subtracting 32768 to get the
original value? But see also the next problem:

2. The 2-byte field is actually holding two data items. The most
significant nybble (which I presume is the top 4 bits) holds one (say
A), with the remaining 12 bits (?) holding the other (B). I have some
documentation that suggests retrieving these values by using:

A = uint & 0xF000

B = uint & 0x0FFF

But I must admit to being stuck as to how to implement these in
VB.Net. I'm guessing that it should be possible to do this either
directly or with a workaround, but what?

Any help much appreciated.

JGD
Nov 21 '05 #1
5 996
John:

Have you looked into System.IO.BinaryReader? It has a slew of methods to
read bits and bytes.

Venkat

"John Dann" wrote:
I'm trying to read some data from a disk file created by a third party
application (written I think in C), so I don't have any option other
than to read/interpret the data in the format in which it's been
saved. There's one particular field giving me problems:

The problematic data item is a 2-byte field saved as an unsigned
integer and has two problems:

1. I know that I can't read a uint directly in to VB.Net (Framework
1.1 at least) as a native type. But presumably there's nothing
stopping me reading it as a short and (?) subtracting 32768 to get the
original value? But see also the next problem:

2. The 2-byte field is actually holding two data items. The most
significant nybble (which I presume is the top 4 bits) holds one (say
A), with the remaining 12 bits (?) holding the other (B). I have some
documentation that suggests retrieving these values by using:

A = uint & 0xF000

B = uint & 0x0FFF

But I must admit to being stuck as to how to implement these in
VB.Net. I'm guessing that it should be possible to do this either
directly or with a workaround, but what?

Any help much appreciated.

JGD

Nov 21 '05 #2

"vvenk" <vv***@discussions.microsoft.com> wrote

Have you looked into System.IO.BinaryReader? It has a slew of methods to
read bits and bytes.


Is slew the right word? Or should that be a plethora? <g>

(From the current .Net Show... ;-)

LFS
Nov 21 '05 #3
On Thu, 14 Oct 2004 05:35:33 -0700, "vvenk"
<vv***@discussions.microsoft.com> wrote:
John:

Have you looked into System.IO.BinaryReader? It has a slew of methods to
read bits and bytes.


Yes I'm actually using BinaryReader to read all of this binary file. I
am reading in the 2-byte field in question as a short, which works
fine (in the sense of not giving any error or interrruption to the
file-reading process). But AFAIK there's no method for reading a uint.
And maybe I could read in the individual bits, but I'd still have the
problem of reconstituting the variables, which is really where I'm
stuck..

I'm fairly sure there are ways to deal with this reading it as a
short, but because I hardly ever have to deal with bit manipulation,
it's not an area of VB where I've much competence/confidence.

JGD
Nov 21 '05 #4

"John Dann" <ne**@prodata.co.uk> wrote

Yes I'm actually using BinaryReader to read all of this binary file. I
am reading in the 2-byte field in question as a short, which works
fine (in the sense of not giving any error or interrruption to the
file-reading process).


I'd suggest you read it in as 2 Bytes, and then just move 4 bits
from one byte to the other as you convert them to Integers:

Dim b1, b2 As Byte
Dim i1, i2 As Integer

b1 = 124
b2 = 39

i1 = b1 \ &H10
i2 = ((b1 And &HF) * &H10000) + b2
HTH
LFS

Nov 21 '05 #5
Larry

Many thanks - much appreciated.

John Dann
Nov 21 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

14
3733
by: Kevin Knorpp | last post by:
Hello. I need to be able to extract the data from the attached file (or any file in the same format) so that I can work with the data in PHP. I'm fairly comfortable with using PHP with...
21
3059
by: nephish | last post by:
i have an interesting project at work going on. here is the challenge. i am using the serial module to read data from a serial input. it comes in as a hex. i need to make it a binary and compare it...
9
6502
by: Ching-Lung | last post by:
Hi all, I try to create a tool to check the delta (diff) of 2 binaries and create the delta binary. I use binary formatter (serialization) to create the delta binary. It works fine but the...
3
3451
by: Arun | last post by:
Hi, I have simple question to ask. How to write multiple Binary files to the Browser using Asp.Net and Visual C#.net I have seen examples where single binary file is written to browser. ...
4
4199
by: Schwarty | last post by:
I hope I posted this to the correct group. If not, please let me know and I will get it posted in the correct section. I have a web application developed in ASP.NET using C# for the code behind....
9
1936
by: ruffiano | last post by:
Hi, can someone tell me if a C++ string (std::string) represents a binary or an ASCII string? Thanks in advance.
15
2970
by: JoeC | last post by:
I am writing a program that I am trying to learn and save binary files. This is the page I found as a source: http://www.angelfire.com/country/aldev0/cpphowto/cpp_BinaryFileIO.html I have...
1
2931
by: girl23 | last post by:
Hi there ]i am new to C programming and totally lost. iam trying to convert decimal to binary. here is what i did please ignore the case h and m. I am trying to get case 'b' to work. i do not...
16
4465
by: Erwin Moller | last post by:
Why is a binary file executable? Is any binary file executable? Is only binary file executable? Are all executable files binary? What is the connection between the attribute of binary and that of...
3
3996
by: Brad | last post by:
I have an aspx page that is sending pdf files to client browsers: it uses a filestream to read the pdf file and response.binarywrite to send content to the browser. This has worked great for years...
0
7171
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
1
7114
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7541
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5693
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
5098
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4751
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3240
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3230
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1607
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.