Binary Flags

I was talking to my friend Toby earlier today, bitching to him about binary flags. I was stuck on an issue with them and was havng a hell of a time getting it sorted out, since I wasn't sure what the flags needed to be.

Anyways, I was having a hard time explaining to him how it works as he is not a developer, but a network guru. So, I put it in his world, since I could demonstrate to him the same process using IP addresses and subnet masks. Another example is the umask in *nix operatin systems. After trying to explain it, I thought I'd put together some sample code showing how this works in the networking world.

Here is a C example showing how one would get the "valid" subnet mask for an IP address:

Toggle C Source for subnet_lookup.c:

The important part of this starts with:

  msb = *(unsigned char *) &adr_inet.sin_addr.s_addr;    if ((msb & 0x80) == 0x00) {       class = 'A';       netmask = "255.0.0.0";   } 

This returns the IP you specified on the command line in the correct format. We then combine that with a hex value to see if it is equal to another hex value. Since IP addresses and subnet masks are 32bit binary, when &'d together, it's like doing binary addition. And how does that work you might ask? Here is an example:

  1 + 1 = 10 (which is 0, you would carry the 1)   0 + 1 = 1   0 + 0 = 0   1 + 0 + 0 = 1   1 + 1 + 0 = 10 (again this is 0, you would carry the 1)   1 + 1 + 1 = 1 (this would be 11, you would carry the 1 here too) 

Okay, confused yet? Good! No, seriously though, it's pretty easy since you can only use 1's or 0's. Here is a more complete example of how binary values would be added together:

01101 + 10111 = 100100  This is why:    0 1 1 0 1 +  1 0 1 1 1 ------------- 1 0 0 1 0 0 

Not so bad huh? Starting from the right, we take 1 + 1, which REALLY is 10. So, it becomes 0, and you "carry" the 1. With me still? great! So, now we take 1 + 0 + 1, which again is 10. This too becomes 0 and you "carry" the 1 again. This time, we take 1 + 1 + 1, which is 11. If you've been following along, you would make it 1, then "carry" the 1.

Anyways, I've rambled way more then I intended to. If you haven't gotten it figured out by now, you either A) have no hope at all, B) consult the Oracle.

Website Update

Lately I have been extremely busy, but since the 1st, things are starting to wind down again. It dawned on me that I need to finish my website. Last month, I decided I would try Blogger and see how I like it. After using it for a month now, I've decided that I'm not going to re-invent the wheel right now and I have post-poned any additional development on my own blog API.

Instead of putting a lot of additional time into what I currently have, I've decided that through the use of a site re-design I can mesh Blogger with the rest of my site. That way, I won't loose any of the backend code for projects, weather, random quotes, etc.

Anways, be prepared to see some major UI changes in the near future. This is currently what I'm starting with, and I have quite a few changes that I would like to make. The first step was getting it to work with Blogger. Getting this to work with the rest of my site should be a snap!

Stay tuned... and let me know what you think.

Tsunami Before/After Satellite Pics

My Mom just sent me this link that shows before and after satellite images of the areas the tsunami struck. I must say... I don't follow the news but I knew it was bad. I had NO clue though it was this bad. Some of these images give the illusion a nuke went off or something!

See for yourself here.

TGIF

OMFG, I'm so fucking glad today is Friday! I don't think I can survive another day this week - geesh! This week was only a 4 day week too, which makes it even worse. Shit started Monday night when I got a message from my neighbor telling me that the water for all 8 units on our property is getting shut off two days later if they haven't been paid.

Now why is she calling me? Well, I'm the Treasurer for our lovely little HOA... just great huh? Tell me about it - it sucks ass... I didn't want the gig in the first place. Anyways, I was rather shocked since I had already mailed a payment. Needless to say, they received it like the same day they caused this stir with my neighbors. BTW, for those who have never been in this situation, it's pretty sweet to have ALL of your neighbors pissed as fuck at you. Hell, I can't blame them though, if I thought my water was going to get shut off and it's -12 outside, trust me, someone would know about it!

So, that's just Monday/Tuesday morning. Tuesday, I get my tickets to visit friends in CA - the one good thing that happened. But, sure enough, not more then 4 hours later, my boss tells me I have to goto CA (same place I vacationing) the beginning of February (same time I'm vacationing) to do on-site work for a client (my previous company). So, I guess my vacation will get cut 2 days short... unless I can get the tickets changed so I can stay an extra 2 days. Either way, things could be worse.

By Wednesday, I still wasn't too sore from boarding and I felt like I should kick it with Ryan, a buddy I used to goto High School with. As I'm getting done with work I check my messages and there is one from Parker, another old friend from High School. He is in town for a wedding. Turns out he wants me to be his guest and it was that night. Funny thing is that the wedding is for one of the first girls I ever went out with - uh, no thanks! Guess it didn't matter though, since I couldn't get ahold of Parker anyways. Therefore I thought it would be a good idea to head down to the Molly with Ryan and some of the players on his Hockey team.

Thursday I thought was going much better. I finally found the root of a problem at work that was perplexing me for a few days. After that, I finished working on some pretty advanced CSS that handles image maps and image roll overs. Finally got some examples done for them too, so hopefully I'll have them posted soon. Since Thursday is our normal bowling night, we had to go bowling. Probably shouldn't actually. There is no school right now, so the place was packed - good thing we got there early. Not that it really mattered though, I did the shittiest that I've done in a LONG time.

Today is Friday though w00tw00t! It has been a good day though. Today Bridger got 3-5 more inches of snow, so it looks like I'll be heading up there sometime this weekend. College kids are starting to get back into town. In fact, I think Ian gets back today from Maui that fucker! Hope he had a good time and brought back some cool shit.

The weekend begins here! =)

Happy New Years!

New years was fun this year. Pretty chill, just partied with some friends. I really had a good time though. There were alot of people out of town, but we were able to round up enough to make it worth while. I know I didn't get off the couch the next day until 4am the following night. I figured that was enough recovery. =)

Sunday was pretty lax too, not much moving. Until Mike the neighbor called. To fill everyone in, Mike the neighbor really isn't MY neighbor but Devin's. He has been watching Devin's house for the past four years, watching tons of parties go down and such but never introduced himself. Well, the last one we had the beginning of December Mike decided he was gonna crash. Needless to say, we are all glad he did. Mike is one cool ass mother fucker!

I also had yesterday off, since Friday was the last day of the year and quarter I had to get as many hours in as I could before then. So, Ryan, Devin and myself decided it would be a great time if we went up to Bridger Bowl and do some boarding, since we had the day off and everyone else had to work. It was really nice too! Sunny, warmed up from +2 when we got there to +22 within a few hours. Warmest day in a while! Not much powder though... so the falls were hard.

It was my first time back on a board since i was 17... I'm almost 25, so I spent alot of time on my ass! =) I didn't feel too bad though, since it was Ryan's first time ever boarding - he's a skiier though. I'm so glad we went though. Even though I felt like I got the shit kicked outa me the next day, I'm still stoked on going, which is good since I have at least two more full day passes.

Maybe if it's nice I'll go again this weekend!