PC Review


Reply
Thread Tools Rate Thread

byte conversion

 
 
Lew Barnesson
Guest
Posts: n/a
 
      18th Dec 2006
Hi,

I have a byte array read from a file using Stream IO, and containing a
mixture of 16-bit integers, strings, etc..

The problem: what is the best way to convert two byte sequences into 16-bit
integers in a way similar to what I used to do with C or C++ formatted IO?

Is there really no direct way to accomplish this without my having to write
my own formatted IO routines? Any help appreciated.

Thanks.

- Lew


 
Reply With Quote
 
 
 
 
Nicholas Paldino [.NET/C# MVP]
Guest
Posts: n/a
 
      18th Dec 2006
Lew,

You can use the static ToInt16 method on the BitConverter class to do
this.

Hope this helps.


--
- Nicholas Paldino [.NET/C# MVP]
- (E-Mail Removed)

"Lew Barnesson" <(E-Mail Removed)> wrote in message
news:b8-dnd-(E-Mail Removed)...
> Hi,
>
> I have a byte array read from a file using Stream IO, and containing a
> mixture of 16-bit integers, strings, etc..
>
> The problem: what is the best way to convert two byte sequences into
> 16-bit integers in a way similar to what I used to do with C or C++
> formatted IO?
>
> Is there really no direct way to accomplish this without my having to
> write my own formatted IO routines? Any help appreciated.
>
> Thanks.
>
> - Lew
>



 
Reply With Quote
 
Lew Barnesson
Guest
Posts: n/a
 
      18th Dec 2006
Nicholas,

Thank you. Exactly what I needed.

On another issue, do you have any counterpart for the C 'Union' construct in
C#?

- Lew
"Nicholas Paldino [.NET/C# MVP]" <(E-Mail Removed)> wrote in
message news:%23c%23$(E-Mail Removed)...
> Lew,
>
> You can use the static ToInt16 method on the BitConverter class to do
> this.
>
> Hope this helps.
>
>
> --
> - Nicholas Paldino [.NET/C# MVP]
> - (E-Mail Removed)
>
> "Lew Barnesson" <(E-Mail Removed)> wrote in message
> news:b8-dnd-(E-Mail Removed)...
>> Hi,
>>
>> I have a byte array read from a file using Stream IO, and containing a
>> mixture of 16-bit integers, strings, etc..
>>
>> The problem: what is the best way to convert two byte sequences into
>> 16-bit integers in a way similar to what I used to do with C or C++
>> formatted IO?
>>
>> Is there really no direct way to accomplish this without my having to
>> write my own formatted IO routines? Any help appreciated.
>>
>> Thanks.
>>
>> - Lew
>>

>
>



 
Reply With Quote
 
Nicholas Paldino [.NET/C# MVP]
Guest
Posts: n/a
 
      18th Dec 2006
Lew,

There really isn't one. You could use the FieldOffset attribute, but
for really complex unions, you will probably have to do something custom.

I would look up the terms "union" and "FieldOffset" in groups.google.com
in order to see previous threads on this subject.


--
- Nicholas Paldino [.NET/C# MVP]
- (E-Mail Removed)

"Lew Barnesson" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> Nicholas,
>
> Thank you. Exactly what I needed.
>
> On another issue, do you have any counterpart for the C 'Union' construct
> in C#?
>
> - Lew
> "Nicholas Paldino [.NET/C# MVP]" <(E-Mail Removed)> wrote
> in message news:%23c%23$(E-Mail Removed)...
>> Lew,
>>
>> You can use the static ToInt16 method on the BitConverter class to do
>> this.
>>
>> Hope this helps.
>>
>>
>> --
>> - Nicholas Paldino [.NET/C# MVP]
>> - (E-Mail Removed)
>>
>> "Lew Barnesson" <(E-Mail Removed)> wrote in message
>> news:b8-dnd-(E-Mail Removed)...
>>> Hi,
>>>
>>> I have a byte array read from a file using Stream IO, and containing a
>>> mixture of 16-bit integers, strings, etc..
>>>
>>> The problem: what is the best way to convert two byte sequences into
>>> 16-bit integers in a way similar to what I used to do with C or C++
>>> formatted IO?
>>>
>>> Is there really no direct way to accomplish this without my having to
>>> write my own formatted IO routines? Any help appreciated.
>>>
>>> Thanks.
>>>
>>> - Lew
>>>

>>
>>

>
>



 
Reply With Quote
 
Lew Barnesson
Guest
Posts: n/a
 
      18th Dec 2006
Nicholas,

Thanks. Good advice. I'll Google (Group) it. :-)

"Nicholas Paldino [.NET/C# MVP]" <(E-Mail Removed)> wrote in
message news:(E-Mail Removed)...
> Lew,
>
> There really isn't one. You could use the FieldOffset attribute, but
> for really complex unions, you will probably have to do something custom.
>
> I would look up the terms "union" and "FieldOffset" in
> groups.google.com in order to see previous threads on this subject.
>
>
> --
> - Nicholas Paldino [.NET/C# MVP]
> - (E-Mail Removed)
>
> "Lew Barnesson" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...
>> Nicholas,
>>
>> Thank you. Exactly what I needed.
>>
>> On another issue, do you have any counterpart for the C 'Union' construct
>> in C#?
>>
>> - Lew
>> "Nicholas Paldino [.NET/C# MVP]" <(E-Mail Removed)> wrote
>> in message news:%23c%23$(E-Mail Removed)...
>>> Lew,
>>>
>>> You can use the static ToInt16 method on the BitConverter class to do
>>> this.
>>>
>>> Hope this helps.
>>>
>>>
>>> --
>>> - Nicholas Paldino [.NET/C# MVP]
>>> - (E-Mail Removed)
>>>
>>> "Lew Barnesson" <(E-Mail Removed)> wrote in message
>>> news:b8-dnd-(E-Mail Removed)...
>>>> Hi,
>>>>
>>>> I have a byte array read from a file using Stream IO, and containing a
>>>> mixture of 16-bit integers, strings, etc..
>>>>
>>>> The problem: what is the best way to convert two byte sequences into
>>>> 16-bit integers in a way similar to what I used to do with C or C++
>>>> formatted IO?
>>>>
>>>> Is there really no direct way to accomplish this without my having to
>>>> write my own formatted IO routines? Any help appreciated.
>>>>
>>>> Thanks.
>>>>
>>>> - Lew
>>>>
>>>
>>>

>>
>>

>
>



 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Conversion to byte Robert Scheer Microsoft VB .NET 3 5th Jul 2010 09:29 PM
Byte[] Conversion shapper Microsoft C# .NET 15 6th Oct 2009 09:36 PM
Marshall::Copy and BYTE* and byte[] conversion? BartMan Microsoft VC .NET 2 29th Oct 2008 06:18 PM
Byte to int Conversion ..?? Sanjay Microsoft VB .NET 4 18th Apr 2006 06:46 PM
Re: C# byte[] conversion to XML Nicholas Paldino [.NET/C# MVP] Microsoft C# .NET 2 17th Aug 2004 03:37 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 04:46 PM.