Friday, April 19, 2013

Floating Points - an explanation for non computer scientists

!!! Attention: this article (and in fact my whole blog) have moved to site:
http://thecsbox.com/2013/05/07/what-are-floating-point-numbers/ !!!


This article is not intended for very proficient programmers or computer scientists, but offers more of an introductory and high level explanation of floating point variables to the hobbyist programmer or high school student who likes to explore computers.

Let's look at Integers first

One of the first variable types you learnt were probably integer variables. With integer variables we can represent integers (i.e. 0, 1, 2, ..., -1, -2, ...). The numbers are represented accurately on the computer, meaning the exact mathematical value can be stored in the computer. However, note that a computer cannot represent the complete infinite set of integers (..., -2, -1, 0, 1, 2, ...) but only a finite subset of it, because a computer's memory is always finite. In C, the two limit values are stored in the constants INT_MIN and INT_MAX.

Getting Real

The limitations of integers are apparent when doing simple divisions like 1 / 3. For code like "int x = 1 / 3" the result would just be rounded down and we'd get 0 for x. This is why computer architects and mathematicians in the early days of computing thought of ways to represent real numbers in the computer. The mathematical set they were interested to do calculations with where the real numbers (containing rational numbers like 1/3 and irrational numbers like pi). The fundamental problem is that the real numbers are an infinite set, but the computer only has finite memory.

Infinity != Infinity ?

Note that with the set of integers, the problem of infinity was solved by specifying two limit values INT_MIN and INT_MAX, such that only the finite subset between those limits can be represented. Now, why can't we just take this approach over to the real numbers? The problem is that the real numbers present a "larger" infinite set than the integers. This was shown in Cantor's famous and lovely proof that the real numbers are an uncountable set whereas integers (and even rational numbers) are a countable set. Anyway, I'm deriving... (I just find these mathematical subtleties very lovely). If you haven't learnt about these concepts before, don't worry. The essential thing we're looking at here is how to represent real numbers in the best possible way on a computer.

Thursday, April 18, 2013

How to prepare for Programming Interviews - Part II

!!! Attention: this article (and in fact my whole blog) have moved to site:
http://thecsbox.com/2013/05/03/how-to-prepare-for-programming-interviews-part-ii/ !!!


I wrote a more general article about how to prepare for coding interviews here. This article talks about how you should work through each individual programming question. I recommend working with the book "Cracking the Coding Interview"


Related Articles:
How to prepare for Programming Interviews - Part I
Should I study Computer Science?
Unix in a Nutshell

Wednesday, April 17, 2013

Reading Notes: Ethernet paper by Metcalfe and Boggs

The paper "Ethernet: Distributed Packet Switching for Local Computer Networks" by Metcalfe and Boggs is THE paper describing Ethernet technology. It appeared in the Communications of the ACM in 1976. Nowadays most wired LANs use Ethernet technology, so its importance is paramount. Below are some of my reading notes.

Synchronization on the Ethernet

In section 6 the author mentions slots as a time unit. In a contention interval the number of slots is calculated to determine how long the station will wait. Furthermore the author explains that the slots are synchronized by the tail of the preceding acquisition interval. In section 4.4 the author defines slots as the maximum time beween starting a transmission and detecting a collision, which is one end-to-end round trip delay. Thus the synchronization via slots depends on the specific physical properties of that network and one can regard slots as the basic time unit for synchronization.

Tuesday, April 16, 2013

How to let items snap-to-grid by default in Finder?

!!! Attention: this article (and in fact my whole blog) have moved to site:
http://thecsbox.com/2013/05/04/finder-items-snap-to-grid-by-default/ !!!


Are you also utterly annoyed that the items in the Finder don't appear in an ordered grid by default, but instead position themselves wherever they were dragged to in the Finder in Mac OS X? This is quite annoying, especially because when making the window smaller, the items don't rearrange themselves but instead hide themselves behind the current window size. Moreover, different items tend to overlap and in general it just makes for a very cluttered appearance.



The solution is to let items sort by name. While commonly also referred to as snap-to-grid, I have found that selecting that option only aligns the items in the grid, but not always in an ordered fashion.

Monday, April 15, 2013

Reading Notes: A Protocol for Packet Network Intercommunication

The paper "A Protocol for Packet Network Intercommunication" by Cerf and Kahn is THE paper about TCP/IP. I'd recommend it to everyone interested in computer networks and specifically TCP/IP. If you have access to the ACM digital library, you can read it here. Below are just some reading notes that can serve as a thinking point.

The paper’s Figures 3 and 4 show and internetwork packet format and a TCP address, respectively. Compare the current ideas of these with the paper’s. What has survived, been discarded, been enlarged or altered, been added?

In the paper the distinction between IP and TCP header is not that clear, or at least not in the way it is today. The internetwork header corresponds to the IP header while the segment format in Fig. 6 corresponds to the TCP header.

Things that are the same
  • Source and destination address in the IP header.
  • Source and destination port in the TCP header.
  • Packet encapsulation with a local header outside the IP header.
  • The notion of gateways, and that routing is performed based on the destination address. Essentially corresponds to lookups in a routing table to determine the next hop ip.

Sunday, April 14, 2013

How to prepare for Programming Interviews - Part I

!!! Attention: this article (and in fact my whole blog) have moved to site:
http://thecsbox.com/2013/05/03/how-to-prepare-for-programming-interviews-part-i/ !!!


Are you a computer science student and currently worried about how best to prepare for your upcoming programming interview? Then hopefully this article where I'm sharing some of my experiences will help you. I have spent extensive time preparing for programming interviews recently and interviewed with Google, Facebook and Microsoft. In the end I decided to go to Facebook for this summer *yay* ;-)


Related Articles:
How to prepare for Programming Interviews - Part II
Should I study Computer Science?

Saturday, April 13, 2013

Macbook can't connect to wireless internet

I have had this strange issue with campus wireless access several times that my iMac or Macbook Air can't connect to the internet, but a Windows machine or my smartphone would connect just fine. The solution that worked for me was going into the Library folder and deleting the SystemsConfiguration folder.

Steps
  1. Go into your hard disk folder, which is usually Macintosh HD.
  2. Then in your hard disk, go into the Library folder and then into the Preferences folder.
  3. Delete the SystemConfiguration folder in there.
  4. Reboot

After rebooting it finally connects to the wireless internet, and the SystemConfiguration folder is also recreated, so you don't need to worry about that.