Posts

Showing posts from March, 2018

Business Yearly Profit/Loss Calculator Coding Challenge (Python)

Image
The Task: The Solution:

Data Structures

Image

Fixed Point Binary

Image
Decimal number can also be represented in binary. It works the same as a normal number, you just add the columns with 1 up on each side of the decimal point: So 4+1 = 5 and 1/2 + 1/4 = 0.75. So the number represented above is 5.75.  Not all decimal numbers can be represented using this method. 

Binary Subtraction

To subtract two binary numbers: Make the number you want to subtract negative (using Two's Compliment), then add it to the original number. E.g: 25-49. 25= 00011001 49 = 00110001 inverse = 11001110 +1 = 11001111 -49 =  11001111 25+(-49) =  00011001+ 11001111  25+(-49) = 11101000

Sign & Magnitude

Image
Represented by replacing the 128 in a bit pattern with a 0 or 1 to represent the sign. The rest of the numbers represent the magnitude as usual (value of number). The 0 represents positive (+) and 1 represents negative (-). As shown in the diagram; the first binary string represents the number 255, the second number instead uses a sign and so represents -127. The lowest number you can represent is -127 because the 128 column has to be replaced by the negative sign. You can still represent numbers up to 255.

Two's Complement

Two's complement is the way most computers represent negative integers. There are three steps: work out -19 in binary 1) Work out the number as a positive.  00010011 <-- This equals 19.  2) Inverse the number. 11101100 3) Add 1. 11101101 <-- This equals -19.  Note: The first byte equalling 0 means the number is positive, the first byte equalling 1 means the number is negative. The range of numbers that can be represented with Two's compliment is -128-127.

ASCII & Unicode

Image
A bit is a singular binary value. 0 or 1/on or off. A byte is a set of 8 bits. E.g: 01101010 All characters in all languages, numbers and punctuation marks etc have to represented using bits and bytes of binary. This is done using character sets. One example of a character set is: ASCII (American Standard Code for Information Interchange) . This uses rows of 7 bits in 128 combinations to represent 128 different characters. Enough for the english language. The first 32 codes are used to represent non-printing characters (space, return key etc). The rest are for letters, numbers and punctuation. In some languages and character sets 128 different combinations was not enough, so Unicode was created. Unicode uses 16 bit sets to make up the characters. This means you can have 65,536 different combinations. Later, Unicode 32 bit was developed which can produce over a million characters. More then enough for all of the different characters from languages, punctuation and emot

Binary, Hexadecimal & Denery

Image
Converting Binary To Hex, Hex To Binary Use the same method for each, just do opposite: Convert Binary To Denery, Denery to Binary Use the same method for each, just do opposite: Convert Denery To Hex, Hex to Denery Convert to Binary then to Denery/Hex.

Binary Addition

Image
Use column addition method. 1 + 1 = 0, carry 1.  1+0 = 1 0+1 = 1 0+0 = 0 If you still have 1 to carry at end of sum then you get an overflow error, where a 9th bit in required to display the most significant number. 

Modular Programming

Modular programming is where a problem is split into sub-tasks until each task can be completed relatively easily. It is an advantage when programming because: Modular programming allows several programmers to work on an individual program at the same time, thus, making development of program faster, as well as allowing modules to be produced by experts in their area. The code base is easier to debug, update, modify and understand, as individual modules can be tweaked if necessary. It leads to a structured approach as a complex problem can be broken into simpler tasks. Modules can be re-used to solve similar problems similar to those that have already been solved, reducing the amount of code which needs to be produced. Modules can be programmed in different languages, which are more appropriate for the specific module.

Global & Local Variables

Variable - a data item that may take on more than one value during the runtime of a program. Local Variable - this type of variable can only be read or modified by the current subroutine itself, this is why a variable can be used in the main program or a different subroutine without an effect. Global Variable - This type of variable is available for any part of the code to read and modify.

Currency Converter Programming Challenge (Python)

Image
The Challenge: My Solution:

Vowel Counter Programming Challenge (Python)

Image
The challenge: My Solution:

Stacks & Queues

Both types of data structures (ways of holding data in computer memory) like arrays. An array is a static data structure meaning its size is always know in advance. When variables are used to point to different elements in arrays, they can become dynamic. Stacks and Queues are dynamic data structures. This means there size can change as they are being used. Stacks Stacks are Last In First Out (LIFO) data structures. This means that the most recent piece of data to be placed on to the stack is the first piece to be taken off it. Adding data to the stack is called Pushing and taking data off the stack is called Popping. They can be difficult to implement. A pointer is used to keep track of the top of the stack. The pointer is incremented when more data is pushed and decreased when popped. Queues Queues are First In First Out (FIFO) data structures. This means that the most recent piece of data to be placed in the queue is the last piece taken out. Queues are usually

JavaScript Coding Basics

Setting Up Document To set up a section of document for JavaScript "<script>" tags must be placed around the JS code: <Script> [JavaScript Code Here] </Script> Outputting Messages On Screen Displaying Messages on a web page can be done by using "document.write": <Script> document.write("Hello World"); </script> If you want an alert pop up box to display above the browser window, "alert" can be used: <Script> alert("Hello World"); </Script> Accepting Inputs If you want to accept data that has not been hard coded, a form with "input id" can be used: <script> <form> Enter data here <input id="userInput", type="string", name="userString"> [a button that saves or outputs the data would be required here] </form> </script> Variables Variables can be set up and used using command "var

Algorithms

Image
An algorithm is a set of instructions that can be followed to complete a desired task. Programmers solve problems using algorithms. Algorithms can be represented using Pseudocode, Flow Charts or simple bullet lists. 4 key Algorithms: Linear search (searching data) - each element in list is searched sequentially until desired data found. This is good because data can be in any random order but also quite inefficient as a lot of data may have to be searched through.  Binary search (searching data) - data set repeatedly divided, value of checked data that is in middle of section, if data value looking for is higher, only top half is searched etc. This is good because not all data needs to be searched, but data does have to be sorted into the correct order. Bubble sort (sorting data) - compares each pair of adjacent items to check if they are in the right order, if not they are swopped. Process repeats.  Insertion sort (sorting data) - takes each pie