473,497 Members | 2,184 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Binary Reader HELP

I will try to make this short and to the point.
I am reading values from a file using a Binary Reader.
At a particular address I can get a value of , Hex 10 or Hex 01 . (varies can be 30, 20, 02,03 etc.)
I need to keep those values as shown..........10 or 01.
And then split the value........ for instance the 10 becomes 1 or 0. (extract either the 1 or the 0 and display it)
Or in the case of the 01,,,,,,,,,,,0 or 1.( extract either the 0 or the 1 and display it)

I have no problem reading the address that contains the values but, I cannot find a way to retain the actual
numbers ( 10 or 01 ) and then split them and display them in a textbox or listbox.
Any ideas would be greatly appreciated.
james

Nov 21 '05 #1
6 1531
Public Function ByteToHex(ByVal b As Byte) As String
Return Hex(&H100 + b).Substring(1)
End Function

This will allways return a string of lenght = 2

regards
Alejandro Lapeyre
"james" <jjames700ReMoVeMe at earthlink dot net> escribió en el mensaje
news:eP**************@tk2msftngp13.phx.gbl...
I will try to make this short and to the point.
I am reading values from a file using a Binary Reader.
At a particular address I can get a value of , Hex 10 or Hex 01 . (varies
can be 30, 20, 02,03 etc.)
I need to keep those values as shown..........10 or 01.
And then split the value........ for instance the 10 becomes 1 or 0.
(extract either the 1 or the 0 and display it)
Or in the case of the 01,,,,,,,,,,,0 or 1.( extract either the 0 or the 1
and display it)

I have no problem reading the address that contains the values but, I cannot
find a way to retain the actual
numbers ( 10 or 01 ) and then split them and display them in a textbox or
listbox.
Any ideas would be greatly appreciated.
james


Nov 21 '05 #2
Alejandro, thanks for the function. Here is what I have going and gets the same results as your function:

dim a as Integer
br.BaseStream.Seek(fieldinfo + 2, SeekOrigin.Begin)' br is a Binary Reader and Seeks fieldinfo (a Hex Address) + 2 positions
'over and then br.ReadByte() reads the byte at that location

a = br.ReadByte() 'reads 1 Byte for Index

a = Hex(a)

ListBox1.Items.Add(" INDEX#: " + (a).ToString())

What I need to have happen is, if the returned value is a 10 , I need only the 1 to be added to the listbox.
and drop the 0. (also this would tell me that the Value is for an Index only........in this case)
If the returned value is 01 I need the 1 (but, from the Right Side of the 01, because the 1 from the Right Side of the 01
would tell me that I have a Currency value and the 1 means that the Currency value has TWO places to the Right of a Decimal
point. (the next value I read with Binary Reader tells me how many numbers to the LEFT of the Decimal are allowed in the field.
I am reading an old (DOS based) Database file header, and getting Field Types and Sizes and that is why I need to split the , 10
or 01 so that I know what type of Field ( regular Numeric or Currency) it is.
james


"alejandro lapeyre" <al**************@jotmail.com> wrote in message news:e1**************@TK2MSFTNGP14.phx.gbl...
Public Function ByteToHex(ByVal b As Byte) As String
Return Hex(&H100 + b).Substring(1)
End Function

This will allways return a string of lenght = 2

regards
Alejandro Lapeyre
"james" <jjames700ReMoVeMe at earthlink dot net> escribió en el mensaje
news:eP**************@tk2msftngp13.phx.gbl...
I will try to make this short and to the point.
I am reading values from a file using a Binary Reader.
At a particular address I can get a value of , Hex 10 or Hex 01 . (varies
can be 30, 20, 02,03 etc.)
I need to keep those values as shown..........10 or 01.
And then split the value........ for instance the 10 becomes 1 or 0.
(extract either the 1 or the 0 and display it)
Or in the case of the 01,,,,,,,,,,,0 or 1.( extract either the 0 or the 1
and display it)

I have no problem reading the address that contains the values but, I cannot
find a way to retain the actual
numbers ( 10 or 01 ) and then split them and display them in a textbox or
listbox.
Any ideas would be greatly appreciated.
james

Nov 21 '05 #3
James,
In addition to the other comments.

It sounds like you want the low nybble or high nybble of a byte.

In VS.NET 2003 you can use the Shift operator, the And operator & the Or
operator to extract or combine each half of a byte.

Dim value As Byte = &H13
Dim high As Byte = HighByte(value)
Dim low As Byte = LowByte(value)

Debug.WriteLine(value.ToString("X2"), "value")
Debug.WriteLine(high.ToString("X1"), "high")
Debug.WriteLine(low.ToString("X1"), "low")

Public Shared Function LowByte(ByVal value As Byte) As Byte
Const mask As Byte = &HF
Return value And mask
End Function

Public Shared Function HighByte(ByVal value As Byte) As Byte
Const mask As Byte = &HF
Return (value >> 4) And mask
End Function

In VS.NET 2003 & later, >> is the right shift operator, while << is the left
shift operator.

Hope this helps
Jay

"james" <jjames700ReMoVeMe at earthlink dot net> wrote in message
news:eP**************@tk2msftngp13.phx.gbl...
I will try to make this short and to the point.
I am reading values from a file using a Binary Reader.
At a particular address I can get a value of , Hex 10 or Hex 01 . (varies
can be 30, 20, 02,03 etc.)
I need to keep those values as shown..........10 or 01.
And then split the value........ for instance the 10 becomes 1 or 0.
(extract either the 1 or the 0 and display it)
Or in the case of the 01,,,,,,,,,,,0 or 1.( extract either the 0 or the 1
and display it)

I have no problem reading the address that contains the values but, I
cannot find a way to retain the actual
numbers ( 10 or 01 ) and then split them and display them in a textbox or
listbox.
Any ideas would be greatly appreciated.
james

Nov 21 '05 #4
enum FieldType
Index = 0
Currency = 1
'...
end enum

dim m_FieldType as FieldType
dim m_DecimalDigits as byte
dim m_SignificantDigits as byte

select case b
case &h10
m_FieldType = FieldType.Index

case 1
m_FieldType = FieldType.Currency
m_DecimalDigits = 2
m_SignificantDigits = ReadNextByte()

case ... ' other field types
case else
debug.writeline("i dont know this field type yet")
end select

"james" <jjames700ReMoVeMe at earthlink dot net> escribió en el mensaje
news:Ox**************@TK2MSFTNGP10.phx.gbl...
Alejandro, thanks for the function. Here is what I have going and gets the
same results as your function:

dim a as Integer
br.BaseStream.Seek(fieldinfo + 2, SeekOrigin.Begin)' br is a Binary Reader
and Seeks fieldinfo (a Hex Address) + 2 positions
'over and then br.ReadByte() reads the byte at that location

a = br.ReadByte() 'reads 1 Byte for Index

a = Hex(a)

ListBox1.Items.Add(" INDEX#: " + (a).ToString())

What I need to have happen is, if the returned value is a 10 , I need only
the 1 to be added to the listbox.
and drop the 0. (also this would tell me that the Value is for an Index
only........in this case)
If the returned value is 01 I need the 1 (but, from the Right Side of the
01, because the 1 from the Right Side of the 01
would tell me that I have a Currency value and the 1 means that the Currency
value has TWO places to the Right of a Decimal
point. (the next value I read with Binary Reader tells me how many numbers
to the LEFT of the Decimal are allowed in the field.
I am reading an old (DOS based) Database file header, and getting Field
Types and Sizes and that is why I need to split the , 10
or 01 so that I know what type of Field ( regular Numeric or Currency) it
is.
james


"alejandro lapeyre" <al**************@jotmail.com> wrote in message
news:e1**************@TK2MSFTNGP14.phx.gbl...
Public Function ByteToHex(ByVal b As Byte) As String
Return Hex(&H100 + b).Substring(1)
End Function

This will allways return a string of lenght = 2

regards
Alejandro Lapeyre
"james" <jjames700ReMoVeMe at earthlink dot net> escribió en el mensaje
news:eP**************@tk2msftngp13.phx.gbl...
I will try to make this short and to the point.
I am reading values from a file using a Binary Reader.
At a particular address I can get a value of , Hex 10 or Hex 01 . (varies
can be 30, 20, 02,03 etc.)
I need to keep those values as shown..........10 or 01.
And then split the value........ for instance the 10 becomes 1 or 0.
(extract either the 1 or the 0 and display it)
Or in the case of the 01,,,,,,,,,,,0 or 1.( extract either the 0 or the 1
and display it)

I have no problem reading the address that contains the values but, I
cannot
find a way to retain the actual
numbers ( 10 or 01 ) and then split them and display them in a textbox or
listbox.
Any ideas would be greatly appreciated.
james


Nov 21 '05 #5
Alejandro, thanks for the code sample. Your help is appreciated.
james

"alejandro lapeyre" <al**************@jotmail.com> wrote in message news:um**************@TK2MSFTNGP10.phx.gbl...
enum FieldType
Index = 0
Currency = 1
'...
end enum

dim m_FieldType as FieldType
dim m_DecimalDigits as byte
dim m_SignificantDigits as byte

select case b
case &h10
m_FieldType = FieldType.Index

case 1
m_FieldType = FieldType.Currency
m_DecimalDigits = 2
m_SignificantDigits = ReadNextByte()

case ... ' other field types
case else
debug.writeline("i dont know this field type yet")
end select

"james" <jjames700ReMoVeMe at earthlink dot net> escribió en el mensaje
news:Ox**************@TK2MSFTNGP10.phx.gbl...
Alejandro, thanks for the function. Here is what I have going and gets the
same results as your function:

dim a as Integer
br.BaseStream.Seek(fieldinfo + 2, SeekOrigin.Begin)' br is a Binary Reader
and Seeks fieldinfo (a Hex Address) + 2 positions
'over and then br.ReadByte() reads the byte at that location

a = br.ReadByte() 'reads 1 Byte for Index

a = Hex(a)

ListBox1.Items.Add(" INDEX#: " + (a).ToString())

What I need to have happen is, if the returned value is a 10 , I need only
the 1 to be added to the listbox.
and drop the 0. (also this would tell me that the Value is for an Index
only........in this case)
If the returned value is 01 I need the 1 (but, from the Right Side of the
01, because the 1 from the Right Side of the 01
would tell me that I have a Currency value and the 1 means that the Currency
value has TWO places to the Right of a Decimal
point. (the next value I read with Binary Reader tells me how many numbers
to the LEFT of the Decimal are allowed in the field.
I am reading an old (DOS based) Database file header, and getting Field
Types and Sizes and that is why I need to split the , 10
or 01 so that I know what type of Field ( regular Numeric or Currency) it
is.
james


"alejandro lapeyre" <al**************@jotmail.com> wrote in message
news:e1**************@TK2MSFTNGP14.phx.gbl...
Public Function ByteToHex(ByVal b As Byte) As String
Return Hex(&H100 + b).Substring(1)
End Function

This will allways return a string of lenght = 2

regards
Alejandro Lapeyre
"james" <jjames700ReMoVeMe at earthlink dot net> escribió en el mensaje
news:eP**************@tk2msftngp13.phx.gbl...
I will try to make this short and to the point.
I am reading values from a file using a Binary Reader.
At a particular address I can get a value of , Hex 10 or Hex 01 . (varies
can be 30, 20, 02,03 etc.)
I need to keep those values as shown..........10 or 01.
And then split the value........ for instance the 10 becomes 1 or 0.
(extract either the 1 or the 0 and display it)
Or in the case of the 01,,,,,,,,,,,0 or 1.( extract either the 0 or the 1
and display it)

I have no problem reading the address that contains the values but, I
cannot
find a way to retain the actual
numbers ( 10 or 01 ) and then split them and display them in a textbox or
listbox.
Any ideas would be greatly appreciated.
james


Nov 21 '05 #6
Jay, again, thank you for your help and code sample(s). Using what you have posted, I am getting this thing whipped. I really
appreciate your help.
I had one table that contained a field that was supposed to be a Currency field, that fooled your code.
That is, until I noticed that the table contained no data and was never referenced in the old application or by any of the other
tables. I guess the original programmer never bothered to remove it from his application or intended to use it one day. But, in
all the other tables that I know are used, and contain Currency fields, using your code (after referencing it correctly
:-),,,,,,,,,,,,my conversion utility correctly identifies all the Currency Fields in tables.
Now, to go and start retreiving the actual data itself and building the Database (Access) with ADOX using the Field data from
the import utility. (fun, fun, fun!)
james

"Jay B. Harlow [MVP - Outlook]" <Ja************@msn.com> wrote in message news:OT**************@TK2MSFTNGP14.phx.gbl...
James,
In addition to the other comments.

It sounds like you want the low nybble or high nybble of a byte.

In VS.NET 2003 you can use the Shift operator, the And operator & the Or operator to extract or combine each half of a byte.

Dim value As Byte = &H13
Dim high As Byte = HighByte(value)
Dim low As Byte = LowByte(value)

Debug.WriteLine(value.ToString("X2"), "value")
Debug.WriteLine(high.ToString("X1"), "high")
Debug.WriteLine(low.ToString("X1"), "low")

Public Shared Function LowByte(ByVal value As Byte) As Byte
Const mask As Byte = &HF
Return value And mask
End Function

Public Shared Function HighByte(ByVal value As Byte) As Byte
Const mask As Byte = &HF
Return (value >> 4) And mask
End Function

In VS.NET 2003 & later, >> is the right shift operator, while << is the left shift operator.

Hope this helps
Jay

Nov 21 '05 #7

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

Similar topics

12
5830
by: Adam J. Schaff | last post by:
I am writing a quick program to edit a binary file that contains file paths (amongst other things). If I look at the files in notepad, they look like: ...
2
1824
by: Mad Scientist Jr | last post by:
i'm trying to read a file byte by byte (and later alter the data and write it to a 2nd file byte by byte) and running into a problem where it seems to keep reading the same byte over and over again...
1
2559
by: young_leaf | last post by:
Hi, What is the most efficient way of making a Binary File Reader, which reads binary file on command of other application. The program: a) Read Binary File b) Create a Table of data based on...
6
2274
by: Klaus Jensen | last post by:
Hi I have some binary files (jpeg), which contain a lot of image-data - and some embedded XML (XMP actually). If I view the file in a hex-editor, there is a lot of binary data - and then in...
23
2787
by: ShaneO | last post by:
Hello, I wish to extract embedded string data from a file using a Binary Read method. The following code sample is used in VB.NET and similar code is used in VB6 - (Assume variable...
6
5775
by: =?Utf-8?B?VGhvbWFzWg==?= | last post by:
Hi, Is it possible to read a file in reverse and only get the last 100 bytes in the file without reading the whole file from the begining? I have to get info from files that are in the last 100...
11
3556
by: Freddy Coal | last post by:
Hi, I'm trying to read a binary file of 2411 Bytes, I would like load all the file in a String. I make this function for make that: '-------------------------- Public Shared Function...
1
4758
by: Gert Conradie | last post by:
The following code can uplaod text files. When i upload a binary file it fail. I might be: 1) using the wrong Encoding 2) will have to System.Convert.ToBase64String the content of the binary...
20
9358
by: tomPee | last post by:
Hi, I've bumbed into a slight problem now, and I just don't seem to know how to fix it. What I want to do is the following: Send over a socket: 1. Number of files to be send (not as an integer,...
0
7120
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
7196
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...
1
6878
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
7373
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
5456
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
4897
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
3088
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
1405
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 ...
1
649
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.