473,944 Members | 1,803 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Convert UInt16 to Byte Array

Hi,

Ok this shud b simple but i cant seem to find it.

I want to convert a System.UInt16 data to 2 Byte array and System.UInt32
data to 4 Byte array ( BigEndian)

something like
Public Sub GetBytes(ByVal n as System.UInt16, ByRef b As Byte())
'Converts the System.UInt16 to a 2 Byte array
void GetBytes( n System.UInt16, Byte b[] )
// Converts the System.UInt16 to a 2 Byte array
* ( UnCompiled)

Sorry if i am asking for a spoon feed :-)

Thanx,
rawCoder
Nov 21 '05 #1
1 2929
"rawCoder" <ra******@hotma il.com> schrieb:
I want to convert a System.UInt16 data to 2 Byte array and System.UInt32
data to 4 Byte array ( BigEndian)


'BitConverter.G etBytes' provides an overload for 'UInt16'/'UInt32', but on
Windows it will work in Little Endian format only. Jon Skeet [MVP] provides
a class named 'EndianBitConve rter' that can be used with Big and Little
Endian format:

Miscellaneous Utility Library
<URL:http://www.yoda.arachs ys.com/csharp/miscutil/>

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>

Nov 21 '05 #2

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

Similar topics

2
29538
by: jiangyh | last post by:
hi there : I have a question about how to convert Type to DbType? thanks a lot. jiangyh
6
10296
by: Ricardo Quintanilla | last post by:
i have a code that sends data to a socket listening over as400 platform, the socket responds to me as a "byte array". then i need to convert the "byte array" into a string. the problem is that the data converted from the byte array into a string , is not what i expect. example: - the data returned from the socket is (byte array) "Usuario Sin Atribuciones Para Esta Función"
3
10376
by: MuZZy | last post by:
Hi, I just wonder if someone can help me wit this - i have a byte array and need to convert it to short array, creating short numbers by combining bytes by pairs: My array: byte, byte, byte, etc. I need: short = byte+byte, short = byte+byte, etc.
1
12074
by: rawCoder | last post by:
Hi, Ok this shud b simple but i cant seem to find it. I want to convert a System.UInt16 data to 2 Byte array and System.UInt32 data to 4 Byte array ( BigEndian) something like Public Sub GetBytes(ByVal n as System.UInt16, ByRef b As Byte()) 'Converts the System.UInt16 to a 2 Byte array
2
2353
by: Howard Weiss | last post by:
I am reading a file (containing short integers). To read the file, I use the following FileStream *myFile = new FileStream(FileName, FileMode::Open, FileAccess::Read); __int64 myFileSize = myFile->get_Length(); Byte myFileData; myFile1Data = new Byte;
6
1778
by: Glenn Wilson | last post by:
I have converted most of the code that I have but am having trouble, mainly with the marked lines. (>>) public static UInt16 checksum( UInt16 buffer, int size ) { Int32 cksum = 0; int counter; counter = 0; while ( size > 0 ) { UInt16 val = buffer;
5
4458
by: Sakharam Phapale | last post by:
Hi All, I am using Microsoft Speech DLL "sapi.dll". I want to use following method of "SpeechLib.SpStream" object (following is a signature which I copied from Quick Info feature of .NET code editor) Public Overridable Overloads Sub BindToFile (Byref pszFileName as System.UInt16 ,eMode as SpeechLib.SPFILEMODE ,ByRef pFormatId as System.Guid ,ByRef pWaveFormatEx as SpeechLib.WaveFormatEx, ullEventInterest as
8
8423
by: Prakash | last post by:
Hi Friends, Using Remoting concept, i have send WCHAR values from VC++.net applicaiton to C# applicaiton. In my C# application it is treated as unsigned shot. I need to convert it back to string and display it. I tried with TypeConverter.GetConverter().ConvertToString() functionality. and String.Format() functionality. But i get the value as "System.UInt16" as string.
5
5436
by: | last post by:
Hi group, Is there an easy way to convert a UInt16 value in to a string which presents it in a binary format. I need a conversion with a fixed length. so 6 must be presented as '0000000000000110' Any help or code examples would be higly appreciated. Thanks a lot in advance,
0
10813
Debadatta Mishra
by: Debadatta Mishra | last post by:
Introduction In this article I will provide you an approach to manipulate an image file. This article gives you an insight into some tricks in java so that you can conceal sensitive information inside an image, hide your complete image as text ,search for a particular image inside a directory, minimize the size of the image. However this is not a new concept, there is a concept called Steganography which enables to conceal your secret...
0
10143
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9971
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
11134
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
11306
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9868
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
7396
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
6313
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4918
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 we have to send another system
3
3518
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.