473,385 Members | 1,927 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Reading a binary field

I have a device hooked up to my COM port that I read data from the serial
port into my program. If the device is in its double mode the information
that comes back is an 8 bit binary field for each record on the machine.
Set up as follows

Bit 7 -- Data type (Set to a 1)
Bit 6 -- Not used (set to 0)
Bits 5 - 0 -- Set to a 1 if the corresponding field is checked on the
machine.

So there are six fields on the machine, if they are checked on the machine I
will get the following:

Field E is marked on the machine:
Field5 Field4 Field3 Field2 Field1 Field0
0 0 0 0 1 0

So I would get from the machine 100000010 or 0x82

Fields A, B and E
Field5 Field4 Field3 Field2 Field1 Field0
1 1 0 0 1 0

So I would get from the machine 10110010 or 0xB2

No columns marked
Field5 Field4 Field3 Field2 Field1 Field0
0 0 0 0 0 0

I would get from the machine 100000000 or 0x80

All Fields marked
Field5 Field4 Field3 Field2 Field1 Field0
1 1 1 1 1 1

So I would get 1011111111 or 0xBF

Etc.

What I need to do is take this value and convert it to a string so I can get
the ones from the binary field and match the selected values from bits 5 to
0 to match on the GUI. Anyone have a clue?

Thanks.

John
Jul 6 '07 #1
1 1544
John,

Assuming you get the data into a variable of type Byte, you can convert that
byte value into a string of ones and zeroes with Convert.ToString.

For example, if you have the input in a byte variable named myByte, to
convert it into a string of ones and zeroes:

Convert.ToString(myByte, 2)

Kerry Moorman
"John Wright" wrote:
I have a device hooked up to my COM port that I read data from the serial
port into my program. If the device is in its double mode the information
that comes back is an 8 bit binary field for each record on the machine.
Set up as follows

Bit 7 -- Data type (Set to a 1)
Bit 6 -- Not used (set to 0)
Bits 5 - 0 -- Set to a 1 if the corresponding field is checked on the
machine.

So there are six fields on the machine, if they are checked on the machine I
will get the following:

Field E is marked on the machine:
Field5 Field4 Field3 Field2 Field1 Field0
0 0 0 0 1 0

So I would get from the machine 100000010 or 0x82

Fields A, B and E
Field5 Field4 Field3 Field2 Field1 Field0
1 1 0 0 1 0

So I would get from the machine 10110010 or 0xB2

No columns marked
Field5 Field4 Field3 Field2 Field1 Field0
0 0 0 0 0 0

I would get from the machine 100000000 or 0x80

All Fields marked
Field5 Field4 Field3 Field2 Field1 Field0
1 1 1 1 1 1

So I would get 1011111111 or 0xBF

Etc.

What I need to do is take this value and convert it to a string so I can get
the ones from the binary field and match the selected values from bits 5 to
0 to match on the GUI. Anyone have a clue?

Thanks.

John
Jul 7 '07 #2

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

Similar topics

3
by: muser | last post by:
With the following code I'm trying to read a text file (infile) and output inaccuracies to the error file (printerfile). The text file is written and stored on disk, while the printerfile has to be...
7
by: John Dann | last post by:
I'm trying to read some binary data from a file created by another program. I know the binary file format but can't change or control the format. The binary data is organised such that it should...
1
by: RML | last post by:
Hi, My VS 2005 VB app reads a binary file that was created by a VS 2005 VC++ WinCE app. The VC++ app writes the following structure to the file. typedef struct { short ID; TCHAR Num; }...
6
by: arne.muller | last post by:
Hello, I've come across some problems reading strucutres from binary files. Basically I've some strutures typedef struct { int i; double x; int n; double *mz;
16
by: Jm.GlezdeRueda | last post by:
Hi all, Im trying to read a 24bit bmp with fread, and i have some problems.. I want to read the whole structure in one time, but i dont know why, it only reads the first member well.. I have...
3
by: katz911 | last post by:
Hello, I've encountered a strange problem which I can't seem to explain. I've written a simple C++ class that deals with a certian binary file. In one of the methods there, I wish to update a...
6
by: John Wright | last post by:
I am trying to read the data from a device on a serial port. I connect just fine and can receive data fine in text mode but not in binary mode. In text mode the data from the device comes in...
6
by: efrenba | last post by:
Hi, I came from delphi world and now I'm doing my first steps in C++. I'm using C++builder because its ide is like delphi although I'm trying to avoid the vcl. I need to insert new features...
2
by: RoddyPiper | last post by:
I am working with a sql server database. Due to a database udgrade, sever fields which were integer are now binary(16). These fields are used for joins later in the VB project. The problem I am...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.