Posts

Converting between binary and decimal representations of IEEE 754 floating-point numbers in C++, Java and Python

Image
This post implements a previous post that explains how to convert 32-bit floating point numbers to binary numbers in the IEEE 754 format. What we have is some C++ / Java / Python routines that will allows us to convert a floating point value into it's equivalent binary counterpart, using the standard IEEE 754 representation consisting of the sign bit, exponent and mantissa (fractional part).

Mixing Managed and Native Types in C++ / CLI

Image
Brief Introduction C++/CLI (Common Language Infrastructure) was designed to bring C++ to .NET as a means of developing managed code applications. Specifically it helps simplify writing managed code when using C++. Suppose you are writing a WinForms application in Microsoft Visual Studio with a view to using C++ to write managed code. You may prefer to reuse existing libraries and headers written in C and C++ but are a little unsure as to how this is achieved exactly.

Mapping Words to Line Numbers in Text Files in STL / C++

Image
Following on from the previous post , this example shows an example of how to use an STL multimap to track the line number(s) associated with each word in a text file. This program essentially reads in text line-by-line, while stripping out all occurrences of punctuation and other non-alphanumeric charcters. Each pair is inserted into the multimap container using the insert function. As with the previous posting, which deals with counting the frequency of words in a file, this example also uses the sample Hamlet.txt file . Code listing as follows: [code language="cpp"] #include <iostream> #include <sstream> #include <fstream> #include <map> using namespace std; int main() { const string path = "/home/andy/NetBeansProjects/Hamlet.txt"; //Linux //const string path = "C:\\Dump\\Hamlet.txt"; ifstream input( path.c_str() ); if ( !input ) { cout << "Error opening file." << endl; ...

Counting the Number of Words in a Text File in STL / C++

Image
This post aims to illustrate the power of using STL's associative arrays as a word counter. It reads the entire contents of the text file, word-by-word, and keeps a running total of the number of occurences of each word. All using just a few lines of code, discounting the bits that output the results.

How to Create an Installer with Microsoft Visual Studio

Image
Introduction Visual Studio 2010 contains a package that enables you to create Windows installer files for your applications. Follow these simple steps to build your own setup package for the Visual Studio application you are working on.

Polymorphism in Java

An example: [code language="cpp"] import java.util.*; public class JavaPolymorph { public void Print() { System.out.println( "JavaPolymorph"); } public static void main(String[] args) { JavaPolymorph j1 = new JavaPolymorph(); JavaPolymorph j2 = new SubJavaPolymorph(); j1.Print(); j2.Print(); } } public class SubJavaPolymorph extends JavaPolymorph { public void Print() { System.out.println( "SubJavaPolymorph"); } } [/code] Giving the output: JavaPolymorph SubJavaPolymorph

Java Threads: The Basics

Method 1: Write a class that implements the Runnable interface (i) Put the thread code in the run() method. (ii) Create a thread object by passing a Runnable object as an argument to the Thread constructor. The Thread object now has a Runnable object that implements the run() method. Like this: (new Thread(new MyThread())).start(); Simple code sample as follows: [code language="java"] package javathread1; class MyThread implements Runnable { public void run() { //Display info about thread System.out.println(Thread.currentThread()); } } public class JavaThread1 { public static void main(String[] args) { // Create the thread Thread thread1 = new Thread(new MyThread(), "thread 1"); // Start the thread thread1.start(); } } [/code] Method 2: Declare the class to be a Subclass of the Thread class (i) Override the run() method from the Thread class to define the ...