<?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; Decimal to Byte array (vice versa)</title>
	<atom:link href="http://www.ms.oyangudi.com/blog/tag/decimal-to-byte-array-vice-versa/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.ms.oyangudi.com/blog</link>
	<description>from Oyangudi...</description>
	<lastBuildDate>Tue, 18 Oct 2011 02:38:17 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Decimal to Byte array (vice versa)</title>
		<link>http://www.ms.oyangudi.com/blog/csharp/decimal-to-byte-array/</link>
		<comments>http://www.ms.oyangudi.com/blog/csharp/decimal-to-byte-array/#comments</comments>
		<pubDate>Thu, 26 Feb 2009 04:13:44 +0000</pubDate>
		<dc:creator>Solomon</dc:creator>
				<category><![CDATA[C#]]></category>
		<category><![CDATA[Decimal to Byte array (vice versa)]]></category>

		<guid isPermaLink="false">http://www.ms.oyangudi.com/blog/?p=35</guid>
		<description><![CDATA[]]></description>
			<content:encoded><![CDATA[<div class="simplesocialbuttons">
<div class="simplesocialbutton ssb-button-googleplus"><!-- Google Plus One--><g:plusone size="medium" count="true" href="http://www.ms.oyangudi.com/blog/csharp/decimal-to-byte-array/"></g:plusone></div>
<div class="simplesocialbutton ssb-button-fblike"><!-- Facebook like--><div id="fb-root"></div><fb:like href="http://www.ms.oyangudi.com/blog/csharp/decimal-to-byte-array/" send="false" layout="button_count" width="100" show_faces="false" action="like" font=""></fb:like></div>
<div class="simplesocialbutton ssb-buttom-twitter"><!-- Twitter--><a name="twitter_share" data-count="horizontal" href="http://twitter.com/share" data-text="Decimal to Byte array (vice versa)" data-url="http://www.ms.oyangudi.com/blog/csharp/decimal-to-byte-array/" class="twitter-share-button" rel="nofollow"></a></div>
</div>
<pre class="brush: csharp; title: ; notranslate">

        /// &lt;summary&gt;
        /// Decimal to Bye array
        /// &lt;/summary&gt;
        /// &lt;param name=&quot;dec&quot;&gt;decimal&lt;/param&gt;
        /// &lt;returns&gt;byte array&lt;/returns&gt;
        public static byte[] DecimalToBytes(Decimal dec)
        {
            using (MemoryStream stream = new MemoryStream())
            {
                using (BinaryWriter writer = new BinaryWriter(stream))
                {
                    writer.Write(dec);

                    return stream.ToArray();
                }
            }
        }

        /// &lt;summary&gt;
        /// Byte array to Decimal
        /// &lt;/summary&gt;
        /// &lt;param name=&quot;src&quot;&gt;byte array&lt;/param&gt;
        /// &lt;returns&gt;decimal&lt;/returns&gt;
        public static Decimal BytesToDecimal(byte[] src)
        {
            if (src.Length == 1)
            {
                return Decimal.Parse(((char)src[0]).ToString());
            }

           using (MemoryStream stream = new MemoryStream(src))
           {
               using (BinaryReader reader = new BinaryReader(stream))
               {
                   return reader.ReadDecimal();
               }

           }
        }
</pre>
<div class="simplesocialbuttons">
<div class="simplesocialbutton ssb-button-googleplus"><!-- Google Plus One--><g:plusone size="medium" count="true" href="http://www.ms.oyangudi.com/blog/csharp/decimal-to-byte-array/"></g:plusone></div>
<div class="simplesocialbutton ssb-button-fblike"><!-- Facebook like--><div id="fb-root"></div><fb:like href="http://www.ms.oyangudi.com/blog/csharp/decimal-to-byte-array/" send="false" layout="button_count" width="100" show_faces="false" action="like" font=""></fb:like></div>
<div class="simplesocialbutton ssb-buttom-twitter"><!-- Twitter--><a name="twitter_share" data-count="horizontal" href="http://twitter.com/share" data-text="Decimal to Byte array (vice versa)" data-url="http://www.ms.oyangudi.com/blog/csharp/decimal-to-byte-array/" class="twitter-share-button" rel="nofollow"></a></div>
</div>
]]></content:encoded>
			<wfw:commentRss>http://www.ms.oyangudi.com/blog/csharp/decimal-to-byte-array/feed/</wfw:commentRss>
		<slash:comments>14</slash:comments>
		</item>
	</channel>
</rss>

