25 November 2008

Boolean Algebra

Basic identities used in boolean algebra digital logic.

Note that X' means not X, the complement of X
  1. X+0 = X
  2. X.1 = X
  3. X+1= 1
  4. X.0 = X
  5. X+X = X
  6. X.X=X
  7. X+X'=1
  8. X.X'=0
  9. X''=X

Other boolean algebra properties.

  • Commutative: X+Y = Y+X
  • Associative: X+(Y+Z) = (X+Y)+Z
  • Distributive: X(Y+Z) = XY + XZ
  • DeMorgan's: (X+Y)' = X'+Y'
The identities below are useful for simpling the logic equations.

  • X(X+Y)=X
  • (X+Y)(X+Y')=X
  • X(X'+Y)=XY
Boolean algebra digital logic tutorial.

BCD Binary Decimal Codes

Binary decimal codes contains 0 to 9 numbers, that is human readable, unlike computer systems use binary number systems 0 and 1s.


































Decimal NumberBCD Digit
00000
10001
20010
30011
40100
50101
60110
70111
81000
91001


BCD example

(215)10 = (0010 0001 0101)BCD



BCD Binary Decimal Codes tutorial

Octal Number System

Octal number system is base-8 system with 8 digits 0 to 7.

Example of a octal number: 147.2

Expanding numbers as a power series with base of 8.

Example of octal number:

(147.2)8 = 1x82 + 4x81 + 7x80 + 2x8-1 = 64 + 32 + 7 + 0.25 = (103.25)10


Octal number system tutorial.

Binary Number System

Binary number system is base-2 system with 2 digits 0 and 1.

Example of a binary number: 1101.1

Binary number can be expanding numbers as a power series with base of 2.

Example:

(1101.1)2 = 1x23 + 1x2 + 0x210 + 1x2-1 = (13.5)10

Binary number 1101.1 is equal to 13.5 in base-10 number system.

Also 1K (kilo) = 210
Also 1M (mega) = 220


Binary number system tutorial

HTML Redirect Tag Page Redirection

Html redirect page tag is inserted between head tags in html page file.

Copy paste HTML redirect tag code below between head tag.


<meta equiv="refresh" content="3;http://alperguc.blogspot.com/">


3 is the duration that html page will wait and after 3 seconds page will redirect to the url.

First parameter of HTML redirect tag is seconds: 3
Second parameter of HTML redirect tag is url: http://alperguc.blogspot.com/

How to redirect html page with refresh tag.

C# WMI Startup Programs, List Startup Applications with ManagementClass

It is possible to list Startup Programs of operating system in C#.

With the use of ManagementClass, a few lines of code will give us this list.
The WMI classes are easy to use such these operations.
  • Add reference System.Management to your project.
  • Add the following code to your code file.
  • using System.Management;
    using System.Management.Instrumentation;
  • Add the code below to list the startup application assigned in os.
  •  ManagementClass mangnmt =
    new ManagementClass("Win32_StartupCommand");

    ManagementObjectCollection mcol = mangnmt.GetInstances();

    foreach (ManagementObject strt in mcol)
    {
    Console.WriteLine("Application Name: "
    + strt["Name"].ToString());

    Console.WriteLine("Application Location: "
    + strt["Location"].ToString());

    Console.WriteLine("Application Command: "
    + strt["Command"].ToString());

    Console.WriteLine("User: " + strt["User"].ToString());
    }

List Autorun programs in C#

C# a generic error occurred in GDI+ Solution

A generic error occurred in GDI+
I encountered this error while I was working with images,
when I try to save image file with EncoderParameter and ImageCodecInfo classes in C#.

This problem is mostly occurred for the security reasons,
you may not enough permission to write file and so on.
Here is solution.
  • Create a System.IO.MemoryStream object.
  • Create a System.IO.FileStream object
  • Save image into MemoryStream
  • Read bytes[] from the MemoryStream
  • Save the image file with FileStream
And Here is the C# sample code;
using System.Drawing.Imaging;
using System.Drawing;
using System.IO;

public static void SaveJpeg
(string path, Image img, int quality)
{
EncoderParameter qualityParam
= new EncoderParameter(System.Drawing.Imaging.Encoder.Quality, quality);

ImageCodecInfo jpegCodec
= GetEncoderInfo(@"image/jpeg");

EncoderParameters encoderParams
= new EncoderParameters(1);

encoderParams.Param[0] = qualityParam;

System.IO.MemoryStream mss = new System.IO.MemoryStream();

System.IO.FileStream fs
= new System.IO.FileStream(path, System.IO.FileMode.Create
, System.IO.FileAccess.ReadWrite);

img.Save(mss, jpegCodec, encoderParams);
byte[] matriz = mss.ToArray();
fs.Write(matriz, 0, matriz.Length);

mss.Close();
fs.Close();
}
Do not forget to close streams, other wise you will get a out of memory error.