<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Solomon &#187; Byte array to Integer (vice versa)</title>
	<atom:link href="http://www.ms.oyangudi.com/blog/tag/byte-array-to-integer-vice-versa/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.ms.oyangudi.com/blog</link>
	<description>from Oyangudi...</description>
	<lastBuildDate>Sat, 21 Aug 2010 11:35:54 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<item>
		<title>Byte array to Integer (vice versa)</title>
		<link>http://www.ms.oyangudi.com/blog/csharp/byte-array-to-integer-vice-versa/</link>
		<comments>http://www.ms.oyangudi.com/blog/csharp/byte-array-to-integer-vice-versa/#comments</comments>
		<pubDate>Thu, 26 Feb 2009 03:59:18 +0000</pubDate>
		<dc:creator>Solomon</dc:creator>
				<category><![CDATA[C#]]></category>
		<category><![CDATA[Byte array to Integer (vice versa)]]></category>

		<guid isPermaLink="false">http://www.ms.oyangudi.com/blog/?p=33</guid>
		<description><![CDATA[/// &#60;summary&#62; /// Byte array to Integer /// &#60;/summary&#62; /// &#60;param name=&#34;bytes&#34;&#62;byte array&#60;/param&#62; /// &#60;returns&#62;int&#60;/returns&#62; public static int BytesToInt(byte[] bytes) { return int.Parse(BytesToString(bytes).Trim()); } /// &#60;summary&#62; /// Byte array to String /// &#60;/summary&#62; /// &#60;param name=&#34;bytes&#34;&#62;byte array&#60;/param&#62; /// &#60;returns&#62;string&#60;/returns&#62; public static string BytesToString(byte[] bytes) { ASCIIEncoding enc = new System.Text.ASCIIEncoding(); return enc.GetString(bytes); } /// &#60;summary&#62; [...]]]></description>
			<content:encoded><![CDATA[<pre class="brush: csharp;">

        /// &lt;summary&gt;
        /// Byte array to Integer
        /// &lt;/summary&gt;
        /// &lt;param name=&quot;bytes&quot;&gt;byte array&lt;/param&gt;
        /// &lt;returns&gt;int&lt;/returns&gt;
        public static int BytesToInt(byte[] bytes)
        {
            return int.Parse(BytesToString(bytes).Trim());
        }

        /// &lt;summary&gt;
        /// Byte array to String
        /// &lt;/summary&gt;
        /// &lt;param name=&quot;bytes&quot;&gt;byte array&lt;/param&gt;
        /// &lt;returns&gt;string&lt;/returns&gt;
        public static string BytesToString(byte[] bytes)
        {
            ASCIIEncoding enc = new System.Text.ASCIIEncoding();

            return enc.GetString(bytes);
        }

        /// &lt;summary&gt;
        /// Integer to Byte array
        /// &lt;/summary&gt;
        /// &lt;param name=&quot;value&quot;&gt;int&lt;/param&gt;
        /// &lt;returns&gt;byte array&lt;/returns&gt;
        public static byte[] IntToBytes(int value)
        {
            ASCIIEncoding enc = new System.Text.ASCIIEncoding();

            return enc.GetBytes(value.ToString());
        }

        /// &lt;summary&gt;
        /// Bytes to Integer
        /// &lt;/summary&gt;
        /// &lt;param name=”src”&gt;&lt;/param&gt;
        /// &lt;returns&gt;&lt;/returns&gt;
        public static int BytesToInt(byte[] src)
        {
             if (src.Length == 1)
                 return (int)src[0];
             else if (src.Length &lt;= 2)
                 return BitConverter.ToInt16(src, 0);

             return BitConverter.ToInt32(src, 0);
         }
</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.ms.oyangudi.com/blog/csharp/byte-array-to-integer-vice-versa/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
