C# - How To Properly Read 16 Byte Unsigned Integer With BinaryReader

Jun 9, 2010

I need to parse a binary stream in .NET to convert a 16 byte unsigned integer. I would like to use the BinaryReader.ReadUIntXX() functions but there isn't a BinaryReader.ReadUInt128() function available. I assume I will have to roll my own function using the ReadByte function and build an array but I don't know if this is the most efficient method?

View 3 Replies


ADVERTISEMENT

Converting Unsigned Byte To Signed Byte?

May 6, 2007

I would like to know how to convert a unisgned byte to signed byte

Atm I got this

a
Function readSignedByte() As SByte
'-128/127
Dim b As SByte

[Code]....

it doesn't work one that well works for numbers positive over 127 if lets say ReadByte() has 128 it would give overflow error which I don't want it to give I would like it to overflow the number to negivate value aka its signed value.

View 5 Replies

Use An Unsigned 32 Bit Integer?

Sep 29, 2011

i want to use an unsigned 32 bit integer. According to [URL]the rage of that type is

UInteger
UInt32
4 bytes
0 through 4,294,967,295 (unsigned)

[code].....

View 7 Replies

Reading Signed And Unsigned Values From A Stream In Both Byte Orders?

May 23, 2011

I need to read signed and unsigned 8 bit, 16 bit and 32 bit values from a file stream which may be little-endian or big-endian (it happens to be a tiff file which carries the byte order indicator at the start).I initially started by writing my own functions to read the values and was able to do so for unsigned values. e.g.

Public Function ReadUInt32() As UInt32
Dim b(4) As Byte
input.Read(b, 0, 4)

[code]....

But then I started looking at signed values and my brain broke.As an alternative, I found the IO.BinaryReader which will let me read signed values directly but doesn't seem to have any way to indicate that the data is big-endian or little-endian.Is there a nice way of handling this? Failing that, can someone tell me how to convert multiple bytes into signed values (in both byte orders)?

View 2 Replies

How To Pass Integer As Unsigned Parameter In .Net

Jul 16, 2010

I'm new to VB.Net. I'm using a library call setInstance(ByVal instance As UInteger) in my VB.Net code. The parameter I need to pass is an Integer. Is there anything I need to do to convert the integer parameter to an unsigned integer? The number is garunteed to be positive and less than 10.

View 3 Replies

Convert A Byte From The Rs232 Port To Unsigned Char Or Any Other Variable To Process It?

Mar 24, 2010

how can i, for example add a datum from the rs232 with other variable here is my code:

Dim ii As Byte
Dim c(100) As Char
c = Me.SerialPort1.ReadExisting()

[Code]....

View 19 Replies

Implementing Two's Complement On Unsigned Integer Types?

Jun 24, 2011

How can I implement a two's complement in VB.NET using unsigned integer types such as Byte, UShort, UInteger and ULong? Can I cast a UInteger to an Integer?

View 1 Replies

64 Bit Unsigned Integer Overflow - In VB 2010 Express Edition ?

Jul 25, 2011

I have an application that deals with some rather large number values. I wanted the values to allow a roll over so I compiled the program with Remove Integer Overflow Checks turned on. The 32 bit numbers roll over just fine but the 64 bit unsigned integers still throw an over flow exception. Is this a bug in the compiler?

View 7 Replies

Convert Positive And Negative Math.Sin (waveform Output Values) Into (unsigned) Byte Array?

Apr 19, 2011

I'm creating an emulator for a device to simulate wave forms. My challenge is that when I try to convert the output of the following code, I can't convert the Math.Sin's double output into byte values that lend themselves to the byte array format required by an existing graphing control as listed at bottom below. I''m not sure how to handle this when the sin function creates negative values but the byte values will need to be positive and basically 'shifted up' so that anything over 127 is negative. (0 - 255) unsigned. BitConverter.GetBytes has been suggested but THIS is the result of that attempt.

[Code]....

View 2 Replies

VS 2010 Signed And Unsigned Integer NOT: For Hex File Checksum Computation?

Feb 22, 2012

I have been trying to compute the checksum for a line of hex code. This is to create a hex file which will be loaded onto an embedded micro.Some of you guys may not know how this is done so very briefly:

a line of hex bytes:

: 10 01 00 00 21 46 01 36 01 21 47 01 36 00 7E FE 09 D2 19 01 40

The underlined bytes are taken and summed. (in this case the decimal 960). and the bold is the checksum Only the 8LSB (or single least significant byte) is needed to compute the checksum... which in this case, 960 = 03C0 in hex, so only C0 is needed.Two's complement is then taken:

step 1) logical not of C0 which is
step 2) add one (integer)
BIN...........DEC...HEX

[code]....

So here is the code I have been using: (quick mention that in the string passed, the hex bytes are all grouped together, there are no space characters)

Public Sub CreateLine(ByVal Data As String)
'Dim BDataArray(DataLength) As Byte
Dim IDataArray(Data.Length) As Integer

[code]....

where i get into trouble is where i commented 'i get into trouble'. My code works, but it's rather crude Now, in that line i first convert the hex value (string) "SChecksum" into an integer. I want to NOT this, so I get my step 2 from my explanation. However, the results appears to be a signed logical NOT. which gives me the wrong answer. My hashed togther version simply subtracts 256 before the not, in order to give me the correct answer.

Basically, I would love for someone to chime in and point out the flaws in my function, and push me towards figuring out the 'proper' way of doing this. Also I can't quite wrap my head around what would happen in the case a string were passed to my function that is over 16 bits, but I imagine I would have to subtract a larger value than 256, before doing the NOT in this case?(whilst we're on the subject of functions, I've used a 'sub', in which case should I used a sub, and which case should I use a function?).

View 4 Replies

Using BinaryReader To Read 15 Bytes?

Jan 28, 2011

I want to read 15 bytes of data starting at byte 40 and ending at byte 55. I then want the value of the 15 bytes of data to print to textbox5. I know this should be a simple task but I'm having a lot of trouble figuring this out.

View 10 Replies

VS 2008 : BinaryReader To Read Bytes?

Apr 11, 2010

Why does this programmer use a binary reader to read bytes, why not the client.getstream.read or streamreader?

Case RequestTags.Connect
'sent from server to client informing client that a successful
'connection negotiation has been made and the connection now exists.

[code]....

View 1 Replies

BinaryReader Class To Read Binary File

Sep 27, 2010

I am using BinaryReader class to read binary file.But I am facing problem while reading number of bytes from it.I have written code to read only 2 bytes from it,it works well on my machine and read only 2 bytes,but when I deployed that code on server machine it read 4 bytes from file.Whats wrong in the code?Is it due to processor i.e.. 32 bit processor/64 bit processor.

View 2 Replies

Combine Byte Arrays, Read Specific Sections, And Then Cut Byte Array At Specified Point?

Apr 6, 2011

Objective: Combine byte arrays, read specific sections, and then cut byte array at specified point.

Private Sub DataArrival(ByRef aBot As xyzSocket, ByRef theData As Byte())
Dim RDLength As Int32
If aBot.ReceivedData Is Nothing Then[code]....

I'm not sure if I have this right to begin with because I can't test it without having it completed.

View 6 Replies

Add High Order Byte To Low Order Byte To Create One Integer Value?

Mar 1, 2010

if a byte value can go up to 255 and two bytes are used to determine the length of packet payload data, how would I convert the two bytes to create one integer value?

State.buffer[13] = 5 and State.buffer[14] = 67
Dim PacketLengthHigh As Integer = state.buffer(13)
Dim PacketLengthLow As Integer = state.buffer(14)

[code]....

View 3 Replies

ASCII To Byte Integer

Sep 7, 2011

I am receiving ASCII data over my serial port. "51 48 46 48 48 49" for example, this represents my temperature of 30.001 degree. Now I would like to convert this ASCII numbers nad combine to readable temperature and store my data into an excel table. [Code]

View 12 Replies

Can Convert An Integer To A Byte

Aug 12, 2009

Can any one tell me how I can convert an integer to a byte. I have a five digit interger and would like to have it as two bytes.

View 3 Replies

Creating A Hex Byte From An Integer?

Feb 25, 2009

I am simply trying to get the hexadecimal value of an integer (below 255) and then place this value into a byte. I have been using the hex command, but it converts the value to a string hex value. Its been driving me mad for days now as I just cant seem to sort it!

The code is as follows:
tempIntToCompare = CInt(tempValue)
tempIntToCompare = tempIntToCompare - LowTemp

[Code]....

View 5 Replies

Integer To Byte Array?

Mar 31, 2010

I want a number like 1000 (hex 3E8) to be 232, 3.

View 2 Replies

Basics Conversion From A Byte To An Integer

May 2, 2011

I'm trying to make to do a widening conversion from a byte to an integer. form has a text box for both Input, and Output, plus a conversion button. [Code] I'm trying to use a catch block, but I'm not certain how it works exactly, and also tried to use an If statement to avert the issue, but that didn't work either. When ever user inputs a number greater than what can be held within the Byte data type the program crashes from the run time error. [Code] and an error message pops up in the compiler saying overflow exception was unhandled.

View 19 Replies

Byte Array To Integer With Bitconverter?

Dec 27, 2011

I am new to vb net so please cut me some slack if this is a stupid question, I have always used vb6 before, but finding that its less and less supported so trying to learn vb.net by myself. Also I am doing this for a hobby not a profession.I am writing an Console application to read a file sequentially 1 byte at a time into a 1 byte buffer. It then copies that byte into a 4 byte lookup buffer, that moves, ie as the file pointer moves forward by one byte the 4 byte lookup buffer copies the last 3 bytes into the first 3 bytes to accept the byte at the file pointer into the 4th byte of the lookup buffer. I am doing 1 byte at a time because the data I am looking for is not at pre-determind offsets and filesizes may not be a multiple of 4.

[Code]...

Help please its driving me mad It appears as if the byte is not being transferred to the lookup buffer so that it would always be 0, either that or I am not converting it to an integer properly

View 5 Replies

Convert An Integer Into A Byte Array?

Jun 15, 2010

I am reading/writing a fixed length header into a stream and I need to do the following in VB:

1. Convert a 2 byte integer (int16) into a byte array

2. Read 2 bytes of a byte array into an integer variable

View 6 Replies

Convert Byte Array To 16 Bit Integer?

Aug 8, 2009

I have a very simple question about converting a byte array into 16bit integers. I am connected to a device through a serial port. It sent me six bytes which represent three Int16 integers. For example, the byte array is called newRecievedData(5) and has a length of 6.

The manual that came with the device claims that the int Format is 8 bit MSB|8 bit LSB. Does that mean the following?

newRecievedData(0) contains 8 high bits of the first Int16
newRecievedData(1) contains 8 low bits of the first Int16
newRecievedData(2) contains 8 high bits of the second Int16

[Code]....

but VB.NET Express 2008 gives me the error that Error 1 Value of type '1-dimensional array of Byte' cannot be converted to 'Short'.

View 2 Replies

Read MemoryStream - Load Image Byte And Read It?

Feb 21, 2012

ok i have image that i bind info in it and i want to read the info now from file (FileStream) its workbut i want to do it not from file so i need to use MemoryStreamhere the example that work and how i do it now how i make it work with MemoryStream (with byte = My.Resources or PictureBox1.image)

Using FS As New IO.FileStream(image, IO.FileMode.Open)
FS.Seek(0, IO.SeekOrigin.End)
While Not FS.ReadByte = Asc("|")

[code].....

View 1 Replies

DB/Reporting :: How To Extract An 8 Byte Integer From CSV To Dataset

Aug 25, 2009

K, I'm not sure which forum this question goes in, so I am putting it here.Here's my problem.I have a customer file [CSV] I am importing to SQL. I am using JET to read it into a dataset. I am using a schema.ini file to define columns, because I have one column with up to 1000 characters in it... so I have to define it as a Memo field so it won't truncate at 255 characters.

View 7 Replies

Return Enum String By Byte / Integer

Oct 6, 2011

I have worked with enums for some time, but i ran in to a little problem.. So i have the Enum:

[Code]...

for example: Dim the_text_value As String = MyStuff(some_func()) ' this returns not "1", but "omg_this_is_one" how can i do this ?

View 3 Replies

.net - Value Of Type '1-dimensional Array Of Byte' Cannot Be Converted To Integer

Jun 5, 2012

I have used the following code to read a memory address from a pointer and offset previously however, Now I've come to use it again and can't figure out how I got it working last time, I'm receiving the error "value of type '1-dimensional array of Byte' cannot be converted to integer" highlighting the BytesAtAddress variable in the ReadProcessMemory calls.

Public Shared Function ReadPointerFromMemory(ByVal BaseAddress As Integer, ByVal PointerOffset As Integer, ByVal BytesToRead As Integer, ByVal pHandle As IntPtr) As Integer
Dim BytesAtAddress As Byte() = New Byte(BytesToRead - 1) {}

[code]....

View 1 Replies

Does BeginSendTo Prefix A Message With A 4 Byte Integer Of The Size

Dec 16, 2010

I inherited a project that includes a dialog between two applications. One in native C++ the other in VB.NET. The protocol is such that the first 4 bytes (32 bits) of the message encodes the size. However the VB.NET side never sets these first four bytes, however it does use the .net method BeginSendTo, which accepts an argument for size. Does the BeginSendTo method automatically add the size to the beginning of the message in the form of a 4 byte int?

View 1 Replies

Keyboard Up / Down Event - Error: KeyCode Is An Integer Not Byte

Jan 30, 2010

Private Declare Sub Keyboard_Event Lib "user32" (ByVal bVk As Byte, ByVal bScan As Byte, ByVal dwFlags As Long, ByVal dwExtraInfo As Long) [Code] I know the KeyCode when i call this function. Example 13 is the keycode for "Enter". But it says that theres an error on syntax cause KeyCode is an integer not Byte. What kind of variable does it need there? I mean does it need the keycode (which is a number) or a character e.g. "a"? [Code]

View 2 Replies

Value Of Type 'Integer' Cannot Be Converted To '1-dimensional Array Of Byte'._

Oct 8, 2010

At the top of the code that follows is the method in c# into which I'm attempting to pass an integer value. Is there anyway I can change the assignment statement to the byte() PDUToSend to take care of the error I currently receive; Value of type 'Integer' cannot be converted to '1-dimensional array of Byte'.

CODE:

View 8 Replies







Copyrights 2005-15 www.BigResource.com, All rights reserved