473,398 Members | 2,088 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,398 software developers and data experts.

converting a 2 bytes hexadecimal value to an integer

Hai
I am writing an application that reads the data from the serial port in to a byte array(example bf).I had converted the byte array to string using
string s=Bitconverter.Tostring(bf)
Now i want to get an integer value from 0th and 1st bytes in bytearray.
the values that comes in my bytearray are
bf[0]=165
bf[1]=03
when it is converted to string it will be A503
i need an integer from bf[0] and bf[1].
please help me
thanks in advance
maya
May 10 '10 #1
1 2008
GaryTexmo
1,501 Expert 1GB
Look at the BitConverter class. It looks like it needs a byte array where the LSB is in the first index. So in your case, if you're looking to get A503, you'll want to have 03 in index 0 and 165 in index 1.

Expand|Select|Wrap|Line Numbers
  1.             byte[] arr = new byte[] { 03, 165 };
  2.             ushort v = BitConverter.ToUInt16(arr, 0);
  3.  
  4.             Console.WriteLine("Value: " + v.ToString());
  5.             Console.WriteLine("Value (Hex): " + v.ToString("X"));
http://msdn.microsoft.com/en-us/library/bb384066.aspx
May 10 '10 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: Todd | last post by:
Our ASP.NET (C#) application accepts form entry and saves inputed data in XML. We are finding that users are sometimes cutting and pasting special characters (from MS Word) into these forms....
2
by: Pushpendra | last post by:
I am storing the encrypted password in xml file which I have saved in unicode format. While I try to read the xml file and create a dataset from it, it shows me the following error ...
1
by: King Kong | last post by:
we are facing this kind of error when we double click the infragistic web grid please help me on this Regards Moid Iqbal Server Error in '/NetworkAccess' Application....
6
by: jasn | last post by:
Hello I am getting the following error message when I try and send an XML sting to a web service, I read somewhere that most web services prefer ascii and some throw errors when using unicode so...
2
by: theonlyzahid | last post by:
Hi, I am getting his weired error when i open my webpage. Parser Error Message: '<', hexadecimal value 0x3C, is an invalid attribute character. Line 13, position 68. Source Error:
1
by: Mike9900 | last post by:
I am getting The ' ' character hexadecimal value 0x20, cannot be included in a name in the following module: public XmlRegistryKey GetSubKey(string path, bool createpath) { XmlElement e = Elem,...
5
by: Just D | last post by:
All, Any valuable idea about subj: "The '%' character, hexadecimal value 0x25" ? I tried to google, but nothing interesting was found. Is it IIS settings problem, user side problem or...
1
by: SanCaziano | last post by:
how can I get get the hexadecimal value of the char insert in a edit control (every time I press a key I want an alert message of its hexadecimal value)
2
by: jerrysc99 | last post by:
I'm getting the following error below. System.Configuration.ConfigurationException: '<', hexadecimal value 0x3C, is an invalid attribute character. Line 8, position 68....
2
by: atulsaxena1981 | last post by:
Dear All, I am working exchange server & fetching task of outlook 2007 through MSXML2.XMLHTTP30 now I am facing the following error "Name cannot begin with the '0' character, hexadecimal...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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
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...
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
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
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
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...

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.