Wednesday, November 18, 2009

C++ Inheritance

Implicit vs Explicit Calls in C++


(Base&)*this = rhs; // IMPLICIT CALL
(*this).Base::operator=(rhs); // EXPLICIT CALL

Tuesday, October 27, 2009

Categorical Syllogisms

I decided to review my Categorical Syllogisms. Since I am a Philosophy major I think its important to stay current in logic as its crucial in any philosophical discussion; perhaps I can go as far as saying logic is the fundamental of any worthwhile discussion. The next few posts will relate to Philosophy and Argumentative Logic.

Today I am reviewing Categorical Syllogism as there are only 5-7 rules of Syllogisms depending on your source. Some sources like to combine syllogistic rules.

A Categorical Syllogism is represented by three terms, a major term (P), a minor term (S) and a middle term (M). The major term is the predicate of the conclusion and the minor term is the subject of the conclusion. The predicate modifies the subject. Traditionally the major term is written first, followed by the minor term and a conclusion. It can be represented as such.

All M are p
All S are M
________
All S are P

To understand how premises are defined we must understand how they are distributed. I have borrowed the list of distributions from Wikipedia and added my own Venn diagrams for ease of learning.

  • In "All A are B"-propositions the subject (A) is distributed.
  • In "No A are B"-propositions both the subject (A) and the predicate (B) are distributed.
  • In "Some A are B"-propositions neither the subject nor the predicate are distributed.
  • In "Some A are not B"-propositions the predicate is distributed.
Distribution of Terms

Fallacy 1: Undistributed Middle
The middle term must be distributed at least once.
Fallacy 2: Illicit Major/Illicit Minor
If a term is distributed in the conclusion, then it must be distributed in a premise.
Fallacy 3: Exclusive Premises
If a term is distributed in the conclusion, then it must be distributed in a premise.
Fallacy 4: Drawing an affirmative conclusion from a negative premise, or drawing a negative conclusion from an affirmative premise.
A negative premise requires a negative conclusion, and a negative conclusion requires a negative premise. (Alternate rendering: Any syllogism having exactly one negative statement is invalid.)
Fallacy 5: Existential Fallacy
If both premises are universal, the conclusion cannot be particular.


Other useful resources:
Lander Edu
Csunx

Friday, March 6, 2009

Programmer Hierarchy

I was recently informed of the hierarchy of programmers chart. Its pretty amusing, however, I have disagree with placing Java at the bottom. As much as I dislike Java, it does have its place. In fact I would place it on par with C# or possibly above it. C# and Java have similar syntax and styling. Both rely on a virtual machine by CLR (common language runtime) and bytecode respectively. C#.Net programs tend to initialize faster than Java programs. However, C# has nowhere near the cross platform capabilities that Java actually does.

None the less, its an interesting read:



http://lukewelling.com/2006/08/03/java-programmers-are-the-erotic-furries-of-programming/

BCD and Binary Conversions

This article is to demonstrate a technique in converting from a standard unsigned integer and into a binary number. Although, this process is rarely complicated, there does rise the occasion where one does need an alternative method.

The current method usually relies on standard libraries or a simple mathematical process. Hexadecimal is converted easily to decimal by multiplying each digit by a power of 16 and adding the results.

However
, large numbers can easily surpass the registers that Intel has given us to with. This renders the provided multiplication and division built in functions unusable.

The first solution many get is to replicate multiplication and division by hand.
                   _25_
ie: 105 / 5 = 5 )105

10
5
This solution is carried out by placing integers into an array and treating the entire process as a series of subtraction. This process gets the jobs done but it negligent of space considering that each digit is represent by 8-bits. The number is therefore in BCD (Binary Coded Decimal).

A BCD is simply every digit converted into its binary equivalent and concatenated. However, the numbers do not actually represent the number in binary.

ie: 765 = 0x2FD = 0b1011111101 = BCDx0111 0110 0101

In this example the binary is two digits short than the BCD, but the advantages of binary can be seen as the numbers get larger. The problems compile trying to add or subtract BCD.

ie 765 = BCDx0111 0110 0101
+426 = BCDx0100 0010 0110
1191 = BCDx1011 1000 1011
11 9 11
6 6

1 0001 1001 0001
1 1 9 1
However, BCD can only represent up to decimal 9, therefore any number greater than five must be added by six. This creates an addition nightmare, and creates tremendous overhead with carrying additional bits. Imagine this process when carrying out division "by hand" method.

If BCD was converted into binary, this would be no problem.

765 = 0b1011111101
426 = 0b0110101010
1191=0b10010100111
The easiest method is a technique I found on hardware conversion from Hex to BCD. This articles technique solves the problem by easily converting the largest set of number to binary without relying on multiplication or division.

Shift and Add-3 Algorithm

  1. Shift the binary number left one bit.
  2. If 8 shifts have taken place, the BCD number is in the Hundreds, Tens, and Units column.
  3. If the binary value in any of the BCD columns is 5 or greater, add 3 to that value in that BCD column.
  4. Go to 1.


Demonstration on Hex to BCD: 0xE


Demonstration on Hex to BCD: 0xFF

The reverse is similar.
  1. Shift bit right.
  2. If bit is greater than 5, subtract three.
  3. Repeat.
The remaining problem is converting unsigned ints to compressed BCD. An unsigned int would be stored such as 6 = 0x0000 0000 0000 0110. The solution is to shift the bits into the unsigned int four bits at a time. Thus having a an array of compressed numbers within unsigned ints. Thus you can think of your array as looking at a long number in binary format through blinders. Think of 16bit real mode, it can only access 64k of memory at a time. Thus you would be accessing your array one "word" at a time.

References:

http://www.engr.udayton.edu/faculty/jloomis/ece314/notes/devices/binary_to_BCD/bin_to_BCD.html