Click here to Skip to main content
Click here to Skip to main content
Articles » Languages » C# » General » Downloads
 

Neural Network OCR

By , 11 Aug 2005
 
Prize winner in Competition "C# Jul 2005"
neuroocr_demo.zip
AForge.Imaging.dll
AForge.Math.dll
AForge.NeuralNet.dll
NeuroOCR.exe
SourceGrid2.dll
SourceLibrary.dll
neuroocr_src.zip
AForge
Math
Math.csproj.user
NeuralNet
Learning
NeuralNet.csproj.user
NeuroOCR
App.ico
NeuroOCR.csproj.user
References
AForge.Imaging.dll
SourceGrid2.dll
SourceLibrary.dll
// AForge Math Library
//
// Copyright � Andrew Kirillov, 2005
// andrew.kirillov@gmail.com
//

namespace AForge.Math
{
	using System;

	/// <summary>
	/// Tools
	/// </summary>
	public class Tools
	{
		// Calculate the power of 2, exp: [0, 30]
		public static int Pow2(int exp)
		{
			return ((exp >= 0) && (exp <= 30)) ? (1 << exp) : 0;
		}

		// Check if the integer is a power of 2
		public static bool IsPowerOf2(int x) 
		{
			return (x & (x - 1)) == 0;
		}

		// Get base of 2 logarithm
		public static int Log2(int x)
		{
			if (x <= 65536)
			{
				if (x <= 256)
				{
					if (x <= 16)
					{
						if (x <= 4)
						{
							if (x <= 2)
							{
								if (x <= 1)
									return 0;
								return 1;
							}
							return 2;
						}
						if (x <= 8)
							return 3;
						return 4;
					}
					if (x <= 64)
					{
						if (x <= 32)
							return 5;
						return 6;
					}
					if (x <= 128)
						return 7;
					return 8;
				}
				if (x <= 4096)
				{
					if (x <= 1024)
					{
						if (x <= 512)
							return 9;
						return 10;
					}
					if (x <= 2048)
						return 11;
					return 12;
				}
				if (x <= 16384)
				{
					if (x <= 8192)
						return 13;
					return 14;
				}
				if (x <= 32768)
					return 15;
				return 16;
			}

			if (x <= 16777216)
			{
				if (x <= 1048576)
				{
					if (x <= 262144)
					{
						if (x <= 131072)
							return 17;
						return 18;
					}
					if (x <= 524288)
						return 19;
					return 20;
				}
				if (x <= 4194304) 
				{
					if (x <= 2097152)
						return 21;
					return 22;
				}
				if (x <= 8388608)
					return 23;
				return 24;
			}
			if (x <= 268435456)
			{
				if (x <= 67108864)
				{
					if (x <= 33554432)
						return 25;
					return 26;
				}
				if (x <= 134217728)
					return 27;
				return 28;
			}
			if (x <= 1073741824)
			{
				if (x <= 536870912)
					return 29;
				return 30;
			}
			return 31;
		}
	}
}

By viewing downloads associated with this article you agree to the Terms of use and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The GNU General Public License (GPLv3)

About the Author

Andrew Kirillov
Software Developer (Senior)
United Kingdom United Kingdom
Started software development at about 15 years old and it seems like now it lasts most part of my life. Fortunately did not spend too much time with Z80 and BK0010 and switched to 8086 and further. Similar with programming languages – luckily managed to get away from BASIC and Pascal to things like Assembler, C, C++ and then C#. Apart from daily programming for food, do it also for hobby, where mostly enjoy areas like Computer Vision, Robotics and AI. This led to some open source stuff like AForge.NET.
 
Going out of computers I am just a man loving his family, enjoying traveling, a bit of books, a bit of movies and a mixture of everything else. Always wanted to learn playing guitar, but it seems like 6 strings are much harder than few dozens of keyboard’s keys. Will keep progressing ...

Permalink | Advertise | Privacy | Mobile
Web01 | 2.6.130617.1 | Last Updated 11 Aug 2005
Article Copyright 2005 by Andrew Kirillov
Everything else Copyright © CodeProject, 1999-2013
Terms of Use
Layout: fixed | fluid