<?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>Ed&#039;s Blog &#187; C/C++</title>
	<atom:link href="http://edmundlong.com/edsBlog/category/cc/feed/" rel="self" type="application/rss+xml" />
	<link>http://edmundlong.com/edsBlog</link>
	<description>Stuff I&#039;m working on at the moment</description>
	<lastBuildDate>Fri, 13 Aug 2010 10:58:36 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>Achieving smooth transparency and glowing</title>
		<link>http://edmundlong.com/edsBlog/achieving-smooth-transparency/</link>
		<comments>http://edmundlong.com/edsBlog/achieving-smooth-transparency/#comments</comments>
		<pubDate>Fri, 13 Aug 2010 10:56:45 +0000</pubDate>
		<dc:creator>Eddie Long</dc:creator>
				<category><![CDATA[C/C++]]></category>

		<guid isPermaLink="false">http://edmundlong.com/edsBlog/?p=282</guid>
		<description><![CDATA[Generally when you want something to flash on and off in a smooth fashion you have a duration that you want an icon to fade in and out at. You then tend to have a timer that increments up to the fade value and when it hits the fade value begins to decrement again down [...]]]></description>
			<content:encoded><![CDATA[<p>Generally when you want something to flash on and off in a smooth fashion you have a duration that you want an icon to fade in and out at. You then tend to have a timer that increments up to the fade value and when it hits the fade value begins to decrement again down to zero. See the code below for an example of this in action</p>
<pre class="brush:cpp">
static const f32 totalFadeTime = 4.0

if (m_fadeUp)
{
	timer += delta;
	if (m_timer > m_revealTime)
	{
		timer = m_revealTime;
		m_fadeUp = false;
	}
}
else
{
	timer -= delta;
	if (timer < 0.0f)
	{
		timer = 0.0f;
		m_fadeUp = true;
	}
}

const f32 alpha = timer / totalFadeTime;

icon->SetAlpha(alpha);
</pre>
<p>The approach above uses linear interpolation so the fade looks quite even and bland. To get a nicer smooth fade you can use sin or cos alongside the linear value to give you a smoother looking effect. This is because of the curve of cos is not linear <a href="http://www.reviewsheetscentral.com/rs/11/mathb/image025.jpg">cos curve</a>. Add the following lines to achieve this effect:</p>
<pre class="brush:cpp">
const f32 alpha = timer / totalFadeTime;
const f32 newAlpha = (cosf(TwoPi * alpha) - 1.0f) * -0.5f;
icon->SetAlpha(alpha);
</pre>
<p>Unfortunately I don&#8217;t have an example of this on hand to show but I does the trick nicely.</p>
<div class="fullcircle-social-links" style="display: block;"></div><div style="clear: both;"></div>]]></content:encoded>
			<wfw:commentRss>http://edmundlong.com/edsBlog/achieving-smooth-transparency/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Just a test</title>
		<link>http://edmundlong.com/edsBlog/just-a-test-2/</link>
		<comments>http://edmundlong.com/edsBlog/just-a-test-2/#comments</comments>
		<pubDate>Sat, 31 Jul 2010 11:41:55 +0000</pubDate>
		<dc:creator>Eddie Long</dc:creator>
				<category><![CDATA[C/C++]]></category>

		<guid isPermaLink="false">http://edmundlong.com/edsBlog/?p=275</guid>
		<description><![CDATA[testing FB and twitter posts]]></description>
			<content:encoded><![CDATA[<p>testing FB and twitter posts</p>
<div class="fullcircle-social-links" style="display: block;"></div><div style="clear: both;"></div>]]></content:encoded>
			<wfw:commentRss>http://edmundlong.com/edsBlog/just-a-test-2/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Tumbleweed</title>
		<link>http://edmundlong.com/edsBlog/tumbleweed/</link>
		<comments>http://edmundlong.com/edsBlog/tumbleweed/#comments</comments>
		<pubDate>Sat, 31 Jul 2010 11:02:33 +0000</pubDate>
		<dc:creator>Eddie Long</dc:creator>
				<category><![CDATA[C/C++]]></category>

		<guid isPermaLink="false">http://edmundlong.com/edsBlog/?p=270</guid>
		<description><![CDATA[It&#8217;s been quiet around here lately. I&#8217;m going to try to make an effort to blog here a bit more, it will mostly be about my SingStar coding experiences!]]></description>
			<content:encoded><![CDATA[<p>It&#8217;s been quiet around here lately. I&#8217;m going to try to make an effort to blog here a bit more, it will mostly be about my SingStar coding experiences!</p>
<div class="fullcircle-social-links" style="display: block;"></div><div style="clear: both;"></div>]]></content:encoded>
			<wfw:commentRss>http://edmundlong.com/edsBlog/tumbleweed/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Uninitialised template compiler warning</title>
		<link>http://edmundlong.com/edsBlog/uninitialised-template-compiler-warning/</link>
		<comments>http://edmundlong.com/edsBlog/uninitialised-template-compiler-warning/#comments</comments>
		<pubDate>Thu, 06 May 2010 08:34:13 +0000</pubDate>
		<dc:creator>edlong</dc:creator>
				<category><![CDATA[C/C++]]></category>

		<guid isPermaLink="false">http://edmundlong.com/edsBlog/?p=259</guid>
		<description><![CDATA[I encountered a rather unintuitive compiler warning yesterday that I&#8217;d thought I&#8217;d share. See the simple templated class below: template class ATemplateClass { public: ATemplateClass() { } virtual ~ATemplateClass() { } void Add() { ++size; } void Reset() { size = 0; } private: int size; }; (for some reason my code output tags are [...]]]></description>
			<content:encoded><![CDATA[<p>I encountered a rather unintuitive compiler warning yesterday that I&#8217;d thought I&#8217;d share. See the simple templated class below:</p>
<pre class="brush:cpp">
template<class T>
class ATemplateClass
{
public:
	ATemplateClass()
	{
	}

	virtual ~ATemplateClass()
	{
	}

	void Add()
	{
		++size;
	}

        void Reset()
	{
		size = 0;
	}

private:
	int size;
};
</pre>
<p>(for some reason my code output tags are doing strange things to liek putting in a </class> and messing up the template tag, grrr!</p>
<p>Obviously this isn&#8217;t what my class is doing but is illustrative of the problem. When attempting to use this class on the stack like so:</p>
<pre class="brush:cpp">
MeanAverage<f32> myTemplate = MeanAverage<f32>();
</pre>
<p>I got the compiler warning:</p>
<blockquote><p>
warning: &#8216;myTemplate &#8216; is used uninitialized in this function
</p></blockquote>
<p>After some head scratching (it is clearly being initialised!) one of my colleagues suggested the reason why I was getting the warning. The &#8216;size&#8217; member of ATemplateClass wasn&#8217;t being initialised in the constructor which seems to have the knock on effect of causing the entire template to appear to not be initialised to the compiler! It may be a particularly strict but it fixes the warning nonetheless, hurrah!</p>
<div class="fullcircle-social-links" style="display: block;"></div><div style="clear: both;"></div>]]></content:encoded>
			<wfw:commentRss>http://edmundlong.com/edsBlog/uninitialised-template-compiler-warning/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>No files were found to look in, Visual Studio 2005</title>
		<link>http://edmundlong.com/edsBlog/no-files-were-found-to-look-in-visual-studio-2005/</link>
		<comments>http://edmundlong.com/edsBlog/no-files-were-found-to-look-in-visual-studio-2005/#comments</comments>
		<pubDate>Mon, 29 Mar 2010 11:19:42 +0000</pubDate>
		<dc:creator>edlong</dc:creator>
				<category><![CDATA[C/C++]]></category>
		<category><![CDATA[Visual Studio]]></category>

		<guid isPermaLink="false">http://edmundlong.com/edsBlog/no-files-were-found-to-look-in-visual-studio-2005/</guid>
		<description><![CDATA[I got this the other day when I was attempting to search for some text. Nothing had visibly changed that I could see and for some reason the search was always returning &#8216;No files were found to look in&#8217; regardless of the search options I entered (i.e. types to search, looking in entire solution, project [...]]]></description>
			<content:encoded><![CDATA[<p>I got this the other day when I was attempting to search for some text. Nothing had visibly changed that I could see and for some reason the search was always  returning &#8216;No files were found to look in&#8217; regardless of the search options I entered (i.e. types to search, looking in entire solution, project etc).</p>
<p>I cannot explain this but focus on Visual Studio and press Ctrl + Scroll Lock fixes it. Yes it is mad and doesn&#8217;t make sense. </p>
<p>Credit goes to: <a href="http://blogs.ugidotnet.org/franny/archive/2005/12/08/31303.aspx">here</a></p>
<div class="fullcircle-social-links" style="display: block;"></div><div style="clear: both;"></div>]]></content:encoded>
			<wfw:commentRss>http://edmundlong.com/edsBlog/no-files-were-found-to-look-in-visual-studio-2005/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>New site content</title>
		<link>http://edmundlong.com/edsBlog/new-site-content/</link>
		<comments>http://edmundlong.com/edsBlog/new-site-content/#comments</comments>
		<pubDate>Tue, 15 Dec 2009 19:23:57 +0000</pubDate>
		<dc:creator>Eddie Long</dc:creator>
				<category><![CDATA[C/C++]]></category>

		<guid isPermaLink="false">http://edmundlong.com/edsBlog/?p=190</guid>
		<description><![CDATA[Hi all, I&#8217;ve just uploaded two new two new projects to the site. The first is a little physics simulation I did last week. The second is an application framework for DirectX that provides a basic scene along with camera setup and manipulation, logging, mesh loading and rendering support and direct input support. You can [...]]]></description>
			<content:encoded><![CDATA[<p>Hi all,</p>
<p>I&#8217;ve just uploaded two new two new projects to the site. </p>
<p>The first is a little physics simulation I did last week.</p>
<p>The second is an application framework for DirectX that provides a basic scene along with camera setup and manipulation, logging, mesh loading and rendering support and direct input support.</p>
<p>You can get them in my <a href="http://www.edmundlong.com/Downloads" target="_blank">downloads section</a> of the site. </p>
<p>Cheers,<br />
Eddie</p>
<div class="fullcircle-social-links" style="display: block;"></div><div style="clear: both;"></div>]]></content:encoded>
			<wfw:commentRss>http://edmundlong.com/edsBlog/new-site-content/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Setting up a basic OpenGL project on Mac OS Leopard and XCode</title>
		<link>http://edmundlong.com/edsBlog/setting-up-a-basic-opengl-project-on-mac-os-leopard-and-xcode/</link>
		<comments>http://edmundlong.com/edsBlog/setting-up-a-basic-opengl-project-on-mac-os-leopard-and-xcode/#comments</comments>
		<pubDate>Sun, 11 Oct 2009 13:46:32 +0000</pubDate>
		<dc:creator>edlong</dc:creator>
				<category><![CDATA[C/C++]]></category>

		<guid isPermaLink="false">http://edmundlong.com/edsBlog/?p=157</guid>
		<description><![CDATA[I&#8217;ve recently setup a basic OpenGL project in XCode to have a black window. In XCode select File->New Project. Select an Empty Project and name it whatever you want, screenie below: Within XCode select Project->New Target again. Select Cocoa on the left then Application and name it whatever you&#8217;d like. You will now see a [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve recently setup a basic OpenGL project in XCode to have a black window.</p>
<p>In XCode select File->New Project. Select an Empty Project and name it whatever you want, screenie below:</p>
<p><br/><br />
<br/></p>
<p><img src="http://edmundlong.com/edsBlog/wp-content/uploads/2009/10/newproject.jpg" alt="newproject" title="newproject" class="alignnone size-full wp-image-161" /></p>
<p><br/><br />
<br/></p>
<p>Within XCode select Project->New Target again. Select Cocoa on the left then Application and name it whatever you&#8217;d like.</p>
<p><br/><br />
<br/></p>
<p><img src="http://edmundlong.com/edsBlog/wp-content/uploads/2009/10/targetapp.jpg" alt="targetapp" title="targetapp" class="alignnone size-full wp-image-162" /></p>
<p><br/><br />
<br/></p>
<p>You will now see a window with a whole bunch of settings. In the General tab press the + button in Linked Libraries. Add OpenGL.Framework and Glut.framework from the list of frameworks in the dialog that appears.</p>
<p><br/><br />
<br/></p>
<p><img src="http://edmundlong.com/edsBlog/wp-content/uploads/2009/10/generalwindow.jpg" alt="generalwindow" title="generalwindow" class="alignnone size-full wp-image-160" /></p>
<p><br/><br />
<br/></p>
<p>Next select Build in the tabs along the top and clear the bottom field GCC_PREFIX_HEADER so that its blank.</p>
<p><br/><br />
<br/></p>
<p><img src="http://edmundlong.com/edsBlog/wp-content/uploads/2009/10/targetsettings.jpg" alt="targetsettings" title="targetsettings" class="alignnone size-full wp-image-163" /></p>
<p><br/><br />
<br/></p>
<p>In the Groups and Files explorer right click on the top level project and select Add->New File. Choose C and C++ and select C file. Again choose whatever name you wish.</p>
<p><br/><br />
<br/></p>
<p><img src="http://edmundlong.com/edsBlog/wp-content/uploads/2009/10/candc_.jpg" alt="candc_" title="candc_" class="alignnone size-full wp-image-159" /></p>
<p><br/><br />
<br/><br />
Paste the following code into the C file:</p>
<pre class="brush:cpp">
#include stdlib.h
#include GLUT/glut.h

void myCustomDisplay(void)
{
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

    glutSwapBuffers();
}

void myCustomReshape(int width, int height)
{
    glViewport(0, 0, width, height);
}

void doSomethingWhenIdle(void)
{
    glutPostRedisplay();
}

int main(int argc, char** argv)
{
    glutInit(&#038;argc, argv);

    glutInitDisplayMode(GLUT_RGBA | GLUT_DOUBLE | GLUT_DEPTH);
    glutInitWindowSize(800, 600);

    glutCreateWindow("My First Window");

    glutDisplayFunc(myCustomDisplay);
    glutReshapeFunc(myCustomReshape);
    glutIdleFunc(doSomethingWhenIdle);

    glutMainLoop();
    return EXIT_SUCCESS;
}
</pre>
<p>Next Build the application using &#8216;Build and Go&#8217; and you&#8217;ll be presented with a 800&#215;600 empty window with the title &#8216;My First Window&#8217;, easy! I won&#8217;t go into the explanation of the different functions, there are plenty of sites out there for that!</p>
<div class="fullcircle-social-links" style="display: block;"></div><div style="clear: both;"></div>]]></content:encoded>
			<wfw:commentRss>http://edmundlong.com/edsBlog/setting-up-a-basic-opengl-project-on-mac-os-leopard-and-xcode/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Display correct text colour on a background colour</title>
		<link>http://edmundlong.com/edsBlog/display-correct-text-colour-on-a-background-colour/</link>
		<comments>http://edmundlong.com/edsBlog/display-correct-text-colour-on-a-background-colour/#comments</comments>
		<pubDate>Thu, 10 Sep 2009 13:10:36 +0000</pubDate>
		<dc:creator>edlong</dc:creator>
				<category><![CDATA[C/C++]]></category>

		<guid isPermaLink="false">http://edmundlong.com/edsBlog/?p=150</guid>
		<description><![CDATA[Hi, I haven&#8217;t posted for a bit, back to some handy C++. I&#8217;ve been working with a lot of text being displayed on a background which can be various colours. Not knowing the background colour is in advance is problematic as if you specify the text colour to be always white and the background colour [...]]]></description>
			<content:encoded><![CDATA[<p>Hi,</p>
<p>I haven&#8217;t posted for a bit, back to some handy C++. I&#8217;ve been working with a lot of text being displayed on a background which can be various colours. Not knowing the background colour is in advance is problematic as if you specify the text colour to be always white and the background colour changes to white then the text is unreadable. Likewise for black and there are a range of colours in between that suffer with the same problem, light grey or dark purple for example. </p>
<p>I needed a way of determining correct text colour based on a given background colour. After doing a little bit of digging I came across this article on <a href=" http://www.codeproject.com/KB/GDI-plus/IdealTextColor.aspx?fid=363054&#038;df=90&#038;mpp=25&#038;noise=3&#038;sort=Position&#038;view=Quick&#038;fr=26">CodeProject</a> which almost gives the solution I was looking for. However I want to just display white or black text depending on the background colour. So here is the code I used to do so, it works remarkably well. I&#8217;ve pseudo coded it up a bit to remove various bits and pieces that may not be important but you can just replace bits of it with proper objects. Also ignore the magic numbers, they&#8217;re there just to show the numbers that worked for me. This algorithm can potentially be used in any language, I&#8217;m using C++ here as it is what I&#8217;m currently using.</p>
<pre class="brush:cpp">
COLOUR GetTextColourFromBackground(COLOUR BackgroundColour)
{
	uint32 uDarkLightColourThreshold(105);
	float fRedThresholdValue(0.299);
	float fGreenThresholdValue(0.587);
	float fBlueThresholdValue(0.114);

	uint8 bgDelta = static_cast<uint8>((BackgroundColour.GetRed() * fRedThresholdValue) + (BackgroundColour.GetGreen() * fGreenThresholdValue) +
		(BackgroundColour.GetBlue() * fBlueThresholdValue));

	COLOUR TextColour(GetColour(White));
	if((255 - bgDelta) < uDarkLightColourThreshold)
	{
		TextColour = GetColour(Black);
	}

	return TextColour;
}
</pre>
<p>So on a white background the text colour returned will be black and on a black background the text colour will be white. Also on a light grey background the colour returned will be black and so on.<br />
The formula used above originally comes from the W3C <a href="http://www.w3.org/TR/AERT#color-contrast">http://www.w3.org/TR/AERT#color-contrast</a>. </p>
<div class="fullcircle-social-links" style="display: block;"></div><div style="clear: both;"></div>]]></content:encoded>
			<wfw:commentRss>http://edmundlong.com/edsBlog/display-correct-text-colour-on-a-background-colour/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Quieten XCode&#8217;s output to the console</title>
		<link>http://edmundlong.com/edsBlog/quieten-xcodes-output-to-the-console/</link>
		<comments>http://edmundlong.com/edsBlog/quieten-xcodes-output-to-the-console/#comments</comments>
		<pubDate>Thu, 06 Aug 2009 18:41:19 +0000</pubDate>
		<dc:creator>Eddie Long</dc:creator>
				<category><![CDATA[C/C++]]></category>

		<guid isPermaLink="false">http://edmundlong.com/edsBlog/?p=146</guid>
		<description><![CDATA[Hi, During some iPhone dev i noticed that the console on my macbook had many entries like: Xcode(19838,0xb0103000) malloc: free_garbage: garbage ptr = 0x319a380, has non-zero refcount = 1 Xcode(19838,0xb0103000) malloc: free_garbage: garbage ptr = 0x31bf6e0, has non-zero refcount = 1 Xcode(19838,0xb0103000) malloc: free_garbage: garbage ptr = 0x3263da0, has non-zero refcount = 1 Xcode(19838,0xb0103000) malloc: [...]]]></description>
			<content:encoded><![CDATA[<p>Hi,</p>
<p>During some iPhone dev i noticed that the console on my macbook had many entries like:</p>
<pre class="brush:plain">
Xcode(19838,0xb0103000) malloc: free_garbage: garbage ptr = 0x319a380, has non-zero refcount = 1
Xcode(19838,0xb0103000) malloc: free_garbage: garbage ptr = 0x31bf6e0, has non-zero refcount = 1
Xcode(19838,0xb0103000) malloc: free_garbage: garbage ptr = 0x3263da0, has non-zero refcount = 1
Xcode(19838,0xb0103000) malloc: free_garbage: garbage ptr = 0x3274eb0, has non-zero refcount = 1
Xcode(19838,0xb0103000) malloc: free_garbage: garbage ptr = 0x319a380, has non-zero refcount = 1
Xcode(19838,0xb0103000) malloc: free_garbage: garbage ptr = 0x31bf6e0, has non-zero refcount = 1
</pre>
<p>These messages I found out are not actually anything to do with my program, I thought I was doing something wrong and not freeing up resources. It is actually the internal workings of XCode which is automatically freeing up resources. Knowing this, I decided to turn off these annoying console outputs and found this <a title="XCode project" href="http://github.com/0xced/quietxcode/zipball/1.1.4">XCode project</a> which basically gobbles up output from XCode in the same mould as above.</p>
<p>Just compile the project and it will install the QuietXCode plugin to <strong>~/Library/Application Support/Developer/Shared/Xcode/Plug-ins. </strong>Restart Xcode and fire up the console and you&#8217;ll see an inital output of:</p>
<pre class="brush:plain">
06/08/2009 19:34:32 Xcode[5147] &lt;QuietXcode&gt; loaded successfully
</pre>
<p>You should no longer see the annoying output!</p>
<div class="fullcircle-social-links" style="display: block;"></div><div style="clear: both;"></div>]]></content:encoded>
			<wfw:commentRss>http://edmundlong.com/edsBlog/quieten-xcodes-output-to-the-console/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Using a single number to contain two other numbers</title>
		<link>http://edmundlong.com/edsBlog/using-a-single-number-to-contain-two-other-numbers/</link>
		<comments>http://edmundlong.com/edsBlog/using-a-single-number-to-contain-two-other-numbers/#comments</comments>
		<pubDate>Fri, 03 Jul 2009 14:46:09 +0000</pubDate>
		<dc:creator>edlong</dc:creator>
				<category><![CDATA[C/C++]]></category>

		<guid isPermaLink="false">http://edmundlong.com/edsBlog/?p=139</guid>
		<description><![CDATA[Hi, Due to a certain restrictive pattern being used at work, I&#8217;ve recently had the need to pass along two numbers but only had a single number to do so. It&#8217;s a bit of a nasty hack but is my first experience with using bit masking and is a useful technique. The integer being used [...]]]></description>
			<content:encoded><![CDATA[<p>Hi,</p>
<p>Due to a certain restrictive pattern being used at work, I&#8217;ve recently had the need to pass along two numbers but only had a single number to do so. It&#8217;s a bit of a nasty hack but is my first experience with using bit masking and is a useful technique. The integer being used in the pattern was an unsigned 32 bit integer and the two other integers I wanted to pass along were both unsigned 8 bit integers. The way we figured to send along the two numbers is to basically use half of the 32 bit integer to contain the two 8 bit integers using masking. The process is very simple there are two functions, Encode and Decode. Encode takes in two integers (I&#8217;ve made them unsigned 16 bits for the moment but you can easily cast the 8 bit unsigned integer to 16 bit) and returns a 32 bit unsigned int that contains the two. The encode function basically shifts the iFirstNumber into the lower 16 bits of the 32 bit integer. Then iSecondNumber is added to this to give a full 32 bit number.</p>
<pre class="brush:cpp">
uint32 Encode(const uint16 iFirstNumber, const uint16 iSecondNumber)
{
	uint32 iEncodedValue((iFirstNumber<< 16) + iSecondNumber);

	return iEncodedValue;
}
</pre>
<p>To explain it a little clearer suppose we have iFirstNumber set to 3 (0x00000011) and iSecondNumber set to 1 (0x00000001) we would end up with the encoded value being 0x0000001100000001</p>
<p>You can see that the first 16 bits contain iFirstNumber and the second 16 bits contain the second. </p>
<p>To get the two numbers back out again we have a similar Decode function:</p>
<pre class="brush:cpp">
void Decode(uint32 iValue, uint16&#038; iFirstNumber, uint16&#038; iSecondNumber)
{
	iFirstNumber = (uint16)((iValue &#038; 0xFFFF0000) >> 16);
	iSecondNumber= (uint16)(iValue &#038; 0x0000FFFF);
}
</pre>
<p>The first number is the overall value ANDed with 0xFFFF0000 and then shifted 16 bits to the right. ANDing the number with 0xFFFF0000 indicates that we are only interested in the first half of the bits in the overall value. It will turn all the rest of the bits in the value to be 0000000000. So after that we will be left with 0x0000001100000000. Now we need to narrow the number down to a 16 bit number. To do this we shift the bits 16 places to the right and cast to a uint16. Casting will remove the proceeding 16 bits(which are all now 0 anyway) and leave us with 0x00000011 which translates to 3.<br />
For iSecondPosition we say that we want only the last half of the bits in the overall value. This leaves us with 0x0000000000000001. Casting this to a uint16 will leave us with 0x00000001 or 1.</p>
<p>In the end we actually didn't need to do it this way but got it working anyhow. Might be handy for someone maybe!</p>
<div class="fullcircle-social-links" style="display: block;"></div><div style="clear: both;"></div>]]></content:encoded>
			<wfw:commentRss>http://edmundlong.com/edsBlog/using-a-single-number-to-contain-two-other-numbers/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
