| « Back into binary | That was remarkably painless » |
Fri, Jan 19, 2007
![[Icon]](rsc/img/chain_link.gif)
I started reading K&R section 2.9 - bitwise operators. And fell at the first hurdle.
Apparently, x = n & 0177 sets to zero all but the low order bits of n.
Of course it does. Obviously. What else would it do?
Err. . .
Okay: Let's think about this. Bitwise operations must mean getting at the actual binary bits that make up an integer, rather than dealing with bytes. But why does one hundred and seventy seven wipe out the high-order bits?
Thank God for C programming notes where I worked out what I was missing: There's a leading zero on that "one hundred and seventy seven"
And leading zeros in programming means what? Yep, it means it's not a decimal value, it's an octal.
Funnily enough, although I can do binary, decimal, or hexadecimal pretty well in my head, octal is a base that just passed me by. Possibly because you can't spell out interesting words on a scientific calculator with it like you can in Hex. . .
So, unable to rely on knowledge, I fell back on the pen & paper I like to keep near me when learning anything, and did a quick working-out of how octal digits work in translation to binary.
0 = 000 1 = 001 2 = 010 3 = 011 4 = 100 5 = 101 6 = 110 7 = 111
And suddenly, everything becomes clear!
177 as an octal translated to binary therefore makes perfect sense:
1 | 7 | 7 001|111|111
Since a byte is eight bits, and 177 equates to seven ones, using the AND operator means that 177 will set the first bit of a byte to zero and leave the rest alone.
So I'll keep my little table of octal-binary conversions at hand, and continue reading this chapter, secure in the knowledge that I do actually understand WTF it's talking about ![]()
Creative Hedgehog
This week has been learning about what a Systems Analyst is, how to think about systems, and to be very aware of gorillas.
Gorillas?
There is a problem with simply asking how the company wants you to solve their problem, or even what they think the problem is. It's called situational blindness, and it [...]
04/03/10 - FIT2001 week 1: beware gorillas!
Hari's corner
How do you awaken a sleepy lawyer in the mornings?
07/03/10 - The Legalease - Episode 10
Place of Stuff
Genesis 19 is a fun little tale, full of reversals and surprises. It begins with two angels going to visit Lot in Sodom. Lot welcomes them in and offers a good foot washing and feeding session. As is polite and in custom with receiving visitors. Especially angels. Shortly after they arrive, the local men turn [...]
27/02/10 - The Bible ? Sod ?Em
Advice From a Single Girl
So I figure I'm like some kind of man whisperer or something.Well, no, that's not quite right, it's more like I'm the guy maturer. See, I just heard that Bird's in a relationship. Bird. And Smith, of course, got married.And the most irresponsible of my exes now has a legitimate grown up career and another has left his job and gone into finance.It's like they break up with me and then go ahead
31/12/69 - They Should Make A Movie About Me
Nation
 
This was possibly the most ridiculous show I have seen in a long time and I can get Sky 1 I know ridiculous. It could be summed up in three sentences Do you know what's in your cereal? Want to? Read the label. Instead it went on for a hour about how evil the cereal [...]
27/10/09 - Dispatches ? do you know what?s in your breakfast? (warning...
Blogroll generated by MagpieRSS
![[Links]](http://geekblog.oneandoneis2.org/skins/112/rsc/img/chain_link.gif)
Dominic can drive for another year! My little Fiesta survived its ordeal by MOT :).
05/03/10
![]()
I last listened to:
The Offspring - She's Got Issues
Most recent photo:
Submersible houseboat