A long explanation of a damned fine joke. PtII.

May 31, 2011

When I last looked at number systems nearly two years ago, I promised to do a follow up to the question “Why”. Why would someone choose to use binary, octal and hexadecimal number-bases instead of the familiar base-10 (decimal) system we use in our day-to-day life. I may have written it over 2 years ago without doing the promised follow-up, but it still seems to be the most visited page on this rather decrepit blog, so I thought I really should start to answer the question.

The answer lies in the fact that computers – as is often stated – store information using two states: ON, and OFF. (Note to the pendantic: this is not strictly true, but is – as they say – a necessary truth for the purposes of discussion).

SR NOR Latch, copyright Napalm Llama

SR NOR Latch

Above is a Flip Flop circuit known as an SR NOR Latch, and it is a very basic form of memory. I will explain briefly how it works, but all you really need to know is that each of the two symbols represent what is known as a logic gate, that logic gates are made of transistors, and that this particular arrangement of transistors means that a value – a ‘state’ – can be kept as ‘memory’.

For those interested in how it works; it rests around a simple statement: if a switch is ON, it is NOT OFF. Similarly, if a switch is OFF, it is NOT ON. Simple, yes? Simple, but it forms the basis of a series of similar ‘statements’ which form the backbone of computing, known as ‘Truth tables’.  A similar statement could be “If I hold a coin in either my left hand OR my right hand, then I hold a coin” and “If I hold a coin in neither of my hands, then I do not hold a coin”. Again, a simple statement, but statements like these really do form the backbone of computing.

Left hand Right hand Left hand OR Right hand

In the SR NOR latch, you can see two large symbols. These symbols represent a NOR gate, where ‘gate’ is simply a term used to describe the electronics that make the gate (transistors and resistors mostly, if you’re curious) and NOR stands for NOT OR. If you look again at the NOR gates, you will see two lines going in from the left – its Inputs – and one line coming out on the right – its output. The gate takes its two inputs and uses a simple rule to generate an output: If both its inputs are OFF, then the output is ON. If any of the two inputs are ON the output is OFF.

Input 1 Input 2 Input 1 NOR Input 2

Above is the truth table for the NOR gate laid out much like the coins in the first table. It is unfortunate that in English ‘nor’ as a word has a very different meaning that NOR using in computing, but then, strictly speaking, the word OR is very different in computing too, but that’s another joke for another time. Suffice to say that NOR mean “Take whatever the result would be if you asked my ‘or’, but give me the opposite”.

Now look at the lines marked ‘S’ and ‘R’. The letters S and R stand for “Set” and “Reset”. You can see each of these lines form one of the inputs of the NOR gates. The second Input of each gate is the Output of the other gate. The series of diagrams below show what happens when you start this system.

In step 1 – when the system is first turned on, we assume all inputs are 0. If all inputs are 0, then both of the outputs – A and B – must be 1. This can be confirmed by looking again at the truth table above. However, the output marked A forms the second input to the ‘S’ NOR, and the output marked B forms the second input to the ‘R’ NOR, giving this:

In step 2, the outputs from the first stage are shown as the inputs B and A. In this case, both NOR gates have one input with at least one line ON (shown here as 1), which means, both outputs come out as 0 – OFF. Take the outputs from this stage, and feed it back in again, and the outputs flip again:

The outputs keep flip-flopping. Left to its own devices, this is utterly useless. However so far we haven’t touched the R or S line. What happens if we put something in the R line?

Simply by briefly setting R to 1, we have changed the nature of the diagram: A and B for the first time are asymmetrical: they hold different values. A is now 0, and B is now 1. Not terribly useful for memory, but what if you now drop R back to 0? You get this:

The system is now stable. So long as you don’t touch S, no matter what else you do to R, A will always remain at 0, and B at 1. This circuit has remembered that at some stage in the past, we toggled the value of R from 0 to 1. What if you want to set the value of A to 1? You toggle S:

Here, we’ve toggled S, but we have a problem: A and B now have the same values. In order for the flip-flop to work as memory, and not simply a system that flips between two states as it was when we started, we need these values to be different (this is what the bars over the Q in the opening image means: “Not Q”, it must hold the value “Not Q” or the thing just doesn’t work). If we hold S for just one more cycle though, we get this:

A and B now hold separate values, and A now has the value 1 – which was our goal originally. As A and B are now asymmetric again, we can release S:


There is nothing particularly special about having to hold S for two cycles, the same is actually true of reseting the system so that A is 0 again (by toggling R).

The important point here is that using a relatively simple piece of electronics that can be described in a diagram using just two symbols, we have working memory (and if you’re really interested, it takes 2 transistors and 6 resistors to make one). It may start off unstable, giving meaningless results, but once it has been deliberately set ON or OFF, it retains that value – it ‘remembers’ the last ‘instruction’ given to it. Incidentally, the term used for when a value is set and retained like this is ‘latched’, thus the name S(et) R(eset) NOR Latch.

Okay, so we can store two states: ON or OFF. But we don’t live in a world where two states should be enough for anyone, we live in a world where entire music collections and literary works are stored in memory, on disks, and transmitted across the internet. We live in a bigger world than ‘on’ and ‘off. So how do we get from these two states, to whole music collections?

Simple really. We just string a lot of them together.

What happens if we string two of these together? Instead of our two states of ON and OFF, we now have four possible states: OFF and OFF, OFF and ON, ON and OFF and ON and ON. By adding another bit of memory, we can now store 4 possible states. If we string one more, we can store EIGHT possible values. String four together? SIXTEEN possible values. String eight of these together and we can store a massive TWO HUNDRED AND FIFTY SIX possible values, just by stringing together 8 little bits of electronics that can be turned ON or OFF. With each consecutive ‘bit’ of memory added, you double the amount of states – the amount of information – that can be recorded.

Which brings us neatly back on to binary: why would anyone use binary instead of our day-to-day decimal? Well, if ON is 1 and OFF is 0, then you have a base-two number system. ON/OFF/OFF/OFF can be written 1000, which in base 2 is 8. ON/ON/OFF/ON can be written 1101, which is 13. Or, to put it another way, if you want to store the meaning of life, the universe, and everything, that can be stored as ON/OFF/ON/OFF/ON/OFF.

So that answers why we use binary, but why Octal and Hexadecimal? The answer to that question is strangely arbitrary, but it’s one that we’re stuck with. I hope to get around to answering that a lot quicker than two years.

(that’s 42, which in binary is 101010)


The Rapture

May 21, 2011

So today is Rapture day, is it? As predicted by Harold Camping, today is the first day of Judgement as predicted by the Bible. Overlooking the utter absurdity of the amount of coverage this strange man has managed to acheive, there’s one slight problem:

He replied “Watch out that you are not deceived. For many will come in my name claiming, ‘I am he.’ and ‘The time is near.’ Do not follow them.

That’s the Bible: Luke 21:8-9. Unfortunately, this passage doesn’t just tell Christians to be wary of weird people screaming “The end is nigh!”, it also contains the very first failed prediction of the coming apolocalypse:

“I tell you the truth, this generation will not pass away until all these things have happened” Luke 21:33.

If the Messiah himself couldn’t accurately predict his own return, I don’t think there’s much hope for American preachers. (Read the whole thing, incidentally, it’s wonderful example of a non-prediction) To be fair, Jesus is also reported to have not known himself what the hell was going on:

“No-one knows about that day or hour, not even the angels in heaven, nor the Son, but only the Father.” (Mathew 24:36)… “Therefore keep your watch, because you do not know on what day your Lord will come. But understand this: If the owner of the house had known at what time of night the thief was coming, he would have kept watch and would not have let his house be broken into. So you also must be ready, because the Son of Man will come at an hour when you do not expect him” (Mathew 24:42-44)

God, it would seem, is clearly not putting his schedule up on Facebook.

There is a serious point here though. The simple fact is that these are not obscure passages, but ones that are constantly referred to in Western Christianity. They are so frequently referred to that I still knew where to find them in the Bible despite being an atheist for some 16 years. This whole charade is a reflection of theology in general: that the believer must dismiss what is plainly written in their sacred texts, and instead believe that only by looking at the Bible in an obscure, slanted way, handed down from on high can the believer be saved.

This is an approach not limited to fringe American preachers getting far too much airtime, but is present every time a religion finds itself on the losing side of a moral argument, or the losing side of a scientific question (i.e. all of the time); when the religion eventually concedes that it screwed up, the religious skew the meaning of their books, and (after giving everyone time to forget just how wrong they were), claim they were in the right all along, if only you read their books “properly” (or “with sophisticated theology”, as is the now-popular term). Once you realise why the rapture is not just silly, but ignores what’s plainly written, you quickly realise why all religions are, frankly, just bloody stupid.

Ken Clarke, and those rape comments

May 18, 2011

Labour are calling for Ken Clarke to be sacked, and half of Twitter is calling for his head on a spike. But based upon what I’m reading, he’s being crucified for saying something he simply did not say.

What’s the issue? The issue is that the government is proposing to allow people who plead guilty to certain crimes – including rape – a reduction of up to 50% the normal sentence. The current maximum is a third off the sentence. The reason for this is that it provides an incentive for a person who is guilty of a crime to confess, and enter a guilty plea at the earliest opportunity, saving everyone a lot of time and money. The incentive is necessary because without it there is no good reason for a person who is guilty of a crime to ever plead guilty – it’s far better to take your chances with the courts as you have nothing to loose and everything to gain.

At this point you may agree or disagree with the degree of the incentive, but let’s be clear that at this point we are simply talking an issue of the degree: should the incentive to plead guilty to a crime be a 33% reduction in a sentence, or should it be a 50% reduction.

People countering the new degree of incentive have latched on to a figure for the average sentence for rape (please note, these are not official figures, these are simply the figures as they were presented in the Radio 4 discussion, and subsequently reported by the BBC). According to people opposed to the change, the average sentence for rape is 5 years. With a guilty plea entered at the earliest opportunity, that sentence would be reduced to 2.5 years, and with a standard release on early license, the sentence served in prison would become 15 months.

Now, what follows is a discussion of the facts discussed. I’m not at this point considering what a sentence for various forms of rape should be, only in the figures being discussed. I have no particular knowledge of sentencing guidelines in the UK. I will, however, point out that the difference being discussed is 5 months: a person sentenced under current guidelines whould serve 20 months in jail of a 5 year sentence assuming everything else is equal.

So this is the complaint put to Ken Clarke on the radio:

If you are talking about halving it to two-and-a-half years and then a person gets out halfway through their sentence on licence which is usual, then we are talking about sentences of 15 months which have no regard at all for the gravity of the offence and gives no time for rehabilitation or training,

To which Ken Clarke responded:

That includes date rape, 17-year-olds having intercourse with 15 year olds..

Serious rape – I don’t think many judges give five years for a forcible rape frankly, the tariff is longer than that. A serious rape with violence and an unwilling woman – the tariff is longer than that.

The BBC interviewer interjected saying

Rape is rape, with respect

To which Clarke responded with:

No it’s not, if an 18-year-old has sex with a 15 year old and she’s perfectly willing, that is rape. Because she is under age, she can’t consent… What you and I are talking about is we are talking about a man forcibly having sex with a woman and she doesn’t want to – a serious crime.

I will put to one side for the moment the initial comment on “Date Rape”, but I will come back to it.

What Clarke has said here regarding sex between consenting teenagers is a serious issue. I may or may not agree with Clarke on this matter (I am far from sufficiently qualified to comment), but it is a widely held viewpoint that consensual sex between teenagers (where consensual is defined as ‘understanding what they’re doing, whilst not being legally able to give consent) is not rape in the same sense as non-consensual sex. Here, Clarke is arguing that this is reflected in the sentencing.

Whether one agrees with Clarke on this matter or not, it is important to understand this point. If Clarke is correct and the 5 year average sentence for rape is skewed towards leniency by cases of consensual sex between teenagers (and, I will emphasise again that I do not know whether this is ture), then claiming that rapists will be “let off” with 15 month prison senetences begins to look suspect. Whether you agree with Clarke or not, this is a reasonable line of defence to take.

The more thorny topic is the “date rape” comment (taken from the BBC):

He also said date rapes were included in the figures which could be “sometimes very confusing” adding: “Date rape can be as serious as the worst rapes but date rapes… in my very old experience of being in trials [from his time as a practising lawyer]… they do vary extraordinarily one from another, and in the end the judge has to decide on the circumstances.”

I am strongly of the position that any non-consensual sex is rape. I am also of the position than if the conditions of consensual sex are not met, that is rape. I have lambasted supporters of Julian Assange for claiming that sex without a condom is not rape: if the woman asks you to wear a condom, and you don’t, it is rape.

It is not, however, unreasonable to note the fact that there are degrees of rape. Before you complain about that statement, let me clarify what those degrees are: the scale rages from Very Serious through Gravely Serious to Extremely Serious. It is not trivialising rape to note that some forms of rape are extremely serious, and some are even more gravely so.

If I were to take serious issue with what Clarke has said it is this: Date Rape is not a valid term. If a woman is raped in her home, in a hotel room or an alleyway, that woman has been raped. The term Date Rape, I believe, trivialises that issue, and possibly makes it harder to convince duries to convict. The term Date Rape should be eradicated.

Ken Clarke may have initially worded his thoughts poorly (the initial “serious rape” terminology that many have seized),  but it is quite clear he is not trivialising rape in the way that many seem to think he is.