• Home
  • Readings
  • Github
  • MIES
  • TmVal
  • About
Gene Dan's Blog

No. 37: Mnemonics for exam MLC (Mustard, Lettuce, Cheese?), Hackers, Euclid, and a Wedding

15 August, 2011 5:37 AM / Leave a Comment / Gene Dan

Hey everyone,

Exam MLC actually stands for “Actuarial Models: Life Contingencies,” but more on that later. Despite having an increasing workload for the third quarter, I’ve still managed to maintain my study schedule and have even had free time for books. Each night before I go to sleep I usually spend 30 minutes or so reading for fun, and I’ve recently finished Stephen Levy’s Hackers: Heroes of the Computer Revolution, which depicts the history of computing from the early days of MIT’s AI Lab and SAIL at Stanford (if you want to go back further to say, Babbage’s Analytical Engine or Ada Lovelace’s programs – you’ll have to look elsewhere) to Wozniak’s Apple II and the formation of Silicon Valley and its mega-corporations up to 1982. The book begins with an introduction to the origins of the term “hacker”, which originated back to the hacks, or pranks that clever students would perform at MIT (well-known hacks include stealing Caltech’s canon, putting firetrucks and police cars on top of the Great Dome, etc.). The term also refers to how early computer enthusiasts would hack together their personal computers from pieces of scrap at the junkyard and throwaway components from large corporations since they didn’t have the luxury to go buy parts from the computer store in the way we can today. I found the book enjoyable and entertaining, but a little lacking because it didn’t present any information past the mid 1980’s before Microsoft’s dominance, since computers have changed dramatically since then.

After reading Hackers, I picked up a copy of Heath’s 1908 translation of Euclid’s Elements – an ancient book on pure Geometry, which I heard about while studying Math in high school but never got around to reading until well after college. The book doesn’t seem difficult – I’d say that the language feels similar to something in between Kafka and Hemingway or that of any typical writer of the early 20th century – without all the messy political allegories or symbolism, though the book is certainly full of symbols! The work itself consists of propositions or theorems  derived from fundamental postulates and definitions, and demonstrates methods for drawing geometric configurations using only a compass and straightedge. The logic flows easily, and right now the most difficult thing for me involves suppressing what I already know – because you have to learn how to not take things for granted when proving things from first principals.

Anyway, my main focus for the next three months involves studying for MLC, and one of the challenges you have to face while studying requires memorizing vast amounts of information since even the most obscure topics can serve as legitimate exam material. One of the techniques I’ve seen my actuarial professor, Jim Daniel use involves associating a cryptic formula with a meaningful phrase, for instance if you want to recall the quadratic formula you say, “x equals the opposite of b, plus or minus the square root of b squared minus four a c, all over two a,” while singing the tune to “Pop Goes the Weasel” in your head. I’ve seen my medical school friends use this method to great success when memorizing chemical compounds. For some strange reason, people have a much easier time memorizing phrases that carry meaning than memorizing seemingly random strings of numbers and letters. I have no idea how that works but until our nation’s best and brightest minds figure out a way for us to download large books into our minds in a quick and efficient way, I’ll have to stick with these strange, and at times, baffling methods. Anyway, when it came to studying for exams, Dr. Daniel liked to use the phrase “old guys go first” to easily recall formulas for benefit reserves. Today I studied formulas for fractional ages while sitting on a plane en route to Houston from Oakland. These formulas interpolate the distribution of deaths between integer years since the tables themselves only have integral data. For instance, the linear interpolation has the form of (1-t)*s(x)+t*s(x+1), exponential interpolation has the form (1-t)*Log(s(x))+t*Log(s(x+1)), and hyperbolic/Balducci interpolation has the form (1-t)/s(x)+t/s(x+t). Memorizing the shape of each interpolation should not present a problem because the terms linear, exponential, and hyperbolic already give the student hints as to what the symbolic expressions should look like. However, memorizing the exact placement and order of the letters x,t and and symbols +/- will give the student headaches. Thus, I came up with the saying “take from the past and give to the future,” which tells the student to use the multiplicative factor (1-t), with the survival function at time x and use the multiplicative factor t for the survival function at time x+t, a time in the future.

In the midst of studying for exams, I managed to fly over to Oakland this weekend to see one of my friends get married. I’ve known her since I was six as my sister’s godparents’ daughter and both our families would visit each other during vacations and I would play Legos and video games with their son when we weren’t trying to beat each other up. I got to see a lot of people that I haven’t seen in ages and I had a really good time. However, I never thought of marriage as something worth the risk with the 40% divorce rate and all, but once I remember asking my college roommate why he decided to play the lottery and he gave me some ridiculous reason along the lines of “if you don’t play, your odds of winning are zero” despite the fact that he studied math in college (sorry man, just picking on you for a second, you’re a cool guy and all). That did get me thinking though (not enough to start playing the lottery), that you can never reach your goals without taking on risk, and that you have to work hard to achieve anything worthwhile in life. For instance, I study hard despite the 50%-75% failure rate on each exam because I want to succeed as an actuary. Likewise, the newlyweds have decided to take the next step despite knowing that they’ll surely face difficult challenges over the next several decades because they know they’ll be happy if they succeed. For that, I admire their leap of faith and wish them the best.

The pictures of the wedding haven’t arrived yet, so here’s a Double-Double from In-n-Out Burger that I had on the way to the wedding:

Posted in: Logs

No. 35: Gonzales Come and Take It Road Race – Race Report

25 July, 2011 1:14 AM / 2 Comments / Gene Dan

Hi everyone,

I haven’t written a race report in a long time and there are some races that will have to be skipped (Chappell Hill, Fort Hood, Walburg, Pace Bend, Fredericksburg, Acadiana) due to time constraints. For a quick summary, I’ll just say that I had some good results at the end of last season (Chappell Hill, Fort Hood – see race results), and some bad results (Walburg, Pace Bend, Fredericksburg, Acadiana) after I decided to upgrade to a higher rank in amateur cycling. This is known as ‘catting up’ through the 5 categories in USA Cycling. Male riders (women have 4 categories) start at “Category 5” and move up through the ranks, to Category 4, 3, 2, and 1, from which professional teams recruit talented riders. Once a male rider reaches category 3 he is considered “pretty good” by his peers, whereas the top two categories contain the elite riders and the bottom 2 categories contain the inexperienced riders. Anyway, in order to move from Cat 5 to Cat 4 a rider needs 10 mass starts in road races or criteriums, to move to higher categories after that a rider needs to place high in finishes in order to earn a requisite number of points. I had 10 starts by the time I left college but I was advised not to move up until I became better. After my results at the end of the season I decided that I was ready to move up, so I submitted my application and was approved for the Men’s 4 races for the 2011 season.

Most competitive cyclists consider category 4 to be not much tougher than category 5, and looking back I find this opinion to be mostly true, but at the beginning of the season I struggled and felt like I would never become good enough to compete at the next level – I had the flu in February and I was dropped after 5 minutes at my season opener at Walburg, and subsequently dropped at the very beginning of the next 4 races. I can attribute some of my lack of performance due to looking for employment during that time period, but some of it was also due to pure laziness. However, at the beginning of March, I was able to secure employment and regain focus – I started riding with the Shama Cycles team every Tuesday at 5:30 AM and eventually reached around 8-10 hours of training per week. At first I dropped at the end of each ride but I eventually became strong enough to keep up, or at least catch up to the group after a hard pull or sprint. Philip Shama, owner of the shop and team worked with me to get the correct fit on the bike and recommended some equipment changes including a lower stem, shorter crank arms, and narrower handlebars. I felt strong enough at the beginning of June to try racing again at Fredericksburg but I still dropped early, although I was able to hang on for about an hour at the Sunday race. This was the first indication that I first started improving so I began to do intervals like I did last year – except with a staggered pattern – 8 x 4 minutes, 4 x 8 minutes, 2 x 16 minutes, and 1 x 32 minutes – 4 sessions of 2 hours each over 2 weeks, take the next week easy, and then start the pattern again the week after. I got about halfway through this schedule when my next set of races came up at Louisiana. I noticed a significant improvement in my time trial speed – about 23 mph, which was far faster than any time trial I had ever done (fastest was 18.9 mph). My friend Ken Day averaged 28 mph over the course, so that pretty much blows my time away – although I know I’m moving in the right direction.

A typical 5:30 AM Tuesday Ride. Photo taken by Philip Shama

During dinner Ken and Jon Sanchez gave me advice on my training – one of the things Ken mentioned was that at the end of each hard workout I should feel tired in a way that I don’t want to ride my bike anymore. However, most of the time I feel like I can ride quite a bit more so as time passes I’ll gradually increase my interval time to cover up most of the 2 hour training blocks – probably up until I have enough stamina to do 2 x 32 minute intervals or 3 x 20 minutes. Also worth noting was including maximum efforts and recovery – both of which I haven’t really been paying attention to. For recovery I’ve been making an effort to get at least 7-8 hours of sleep, since in March I was getting about 6 each day. Both of them advised me to also be aggressive while racing. Even though I may get a better result by sitting in the pack and conserving energy, I’ll be gaining better fitness if I attack and be aggressive off the front – even if that means dropping later on. It’s better to learn these things now than to wait until moving to Category 3 to try them and make mistakes. So on the next day’s road race, I tried staying near the front and taking pulls to bring back a breakaway – after about 2 hours I was pretty much spent so I used my last ounce of energy pulling my teammate Doug Baysinger back to the front after Jim Perrin, the eventual winner, attacked the bunch. I dropped off the back after that last pull but hopefully that effort let Doug, whom I knew was stronger, save some energy. If I had stayed near the back I’m pretty sure I would have been able to get a pack finish but I did learn a lot about what goes on in the front – and like Ken said, it definitely is smoother up there.

Alright – so here’s the main race report. After completing a schedule of intervals I felt strong going in to today’s race, Come and Take It at Gonzales Texas. I woke up at 4AM and went out to McDonald’s but found out it was closed, so I ate some caffeinated energy blocks to keep me awake until I reached another McDonald’s about an hour west on I-10, where I loaded up on 2 cups of coffee, a hash brown, and a sausage McMuffin. After I reached the course, I warmed up for about 20 minutes and met up with Doug, but I found out he was racing in the 35+ category so we wouldn’t be racing together. However, when I made my way to the starting line I found another Shama Cycles member, Bill Krause. Before the start, I saw that there were some heavy hitters – James Perrin of Bike Barn – who won Acadiana, and Tak Makino and Jaxson Appel of Texas Pro Health. I had ridden with these three riders each Saturday over the last year and I knew they would be strong. However, I only had one main objective for the race and that was to stay with the bunch until the finish since I hadn’t done that since I moved up to Cat 4. I felt pretty good about the course because it didn’t include most of the things that I’m bad at – such as strong winds, technical turns, or long climbs, but that also meant that the pace would be high when chasing down breakaways so I would have to pay attention to any unexpected surges that might happen. At the start, the pace was tough – around 27mph – 31mph as some people tried moving off the front but Jim, Tak, and Jaxson kept the race under control and no one got very far. About midway through the course Bill attacked off the front so I sat back and let the others do the chasing. Unfortunately he was caught shortly after but managed to stay with the pack. I moved up to the front right before they caught him and I was contemplating a counterattack, but I figured that I needed to focus on my objective so I pulled for a couple of minutes and moved back after a turn.

Tak Makino of Texas Pro Health rounds a corner during the crit on the previous day. Photo credit goes to Propaganda Bike Shop.

For the last 11 miles, attacks were coming quite frequently and every time the bunch chased them down. The hills were also getting steeper so this was when my legs began to hurt and run out of energy. Bill asked me how I was doing and I told him I was okay, but I was worried that I would get dropped. However, it was mostly the rough road vibration that was making me uncomfortable, and in terms of stamina I felt like I had a good amount left. At about 4 miles to go there was a steep hill and I knew this was where the final selection would be made, so I told myself that I was going to give it my all to stay with the pack on this hill – fortunately it was a lot easier than it looked and I felt fine after we went up it, and at this point I knew I had met my objective and that I wouldn’t drop toward the end. About 2 miles to the finish I started planning an attack, and about half a mile later Jim went on an attack – I yelled at the bunch to keep in contact with him as he was dangerous – and we did, and after that more people tried moving off the front and that’s when I decided to attack – however another rider was blocking my position and I kept screaming at him to either move up or move out of the way but he didn’t budge – I don’t know if he did that on purpose or if he was too tired to move. Anyway, I was angry but it was my fault for not being in the front earlier – so I moved all the way around to the other side and moved up front for the bunch sprint. I kicked in at about 200 meters to go but it was a little too early – I passed Jim, but Tak and Jaxson and the eventual winner passed me up and when I reached the line I counted 8 bodies in front of me, so I thought I got 9th or 10th place, but it’s hard to tell when everyone is so close and you’re not sure who passed whom and when. However, as I was packing my things Bill Fiser told me that I had gotten 7th and my first points towards my Cat 3 upgrade! I was pretty happy with the result but I think I had enough energy to take the win had I positioned myself better earlier. The course speed averaged 23.7 mph, so the speed has been steadily creeping up as the year moves on.

The peloton charges up the final hill, riders jockeying for position. Photo by Rouse Bicycles.

Right now everyone is telling me that I must have it easy on the climbs but I actually find that to be a weakness and I get dropped easily on long climbs – it’s hard to discover your strengths at an early stage but I think I’m developing into more of a puncheur – one who is not a pure sprinter with top speed but can accelerate quickly and go on short breakaways- since I’ve done last minute breakaways before and can finish high in the bunch sprint if I don’t get dropped, but I’m not sure yet because I’m still learning. There is something glamorous about being able to hold off a charging bunch after an attack so I’m hoping that’s what I’ll become, although it may very well be that I’m genetically a climber. Anyway I think right now it’s more important to focus on my weaknesses because if I don’t do that I won’t be able to get myself into a position to use my strengths. So, I’ll hold off on max efforts for now and focus on stamina and resisting the wind through my interval schedule, and work on my cornering at Memorial Park. My goals for the next race, Chappell Hill, are to be aggressive and ride at the front – although from my experience it will be hard for a breakaway to succeed, depending on the weather. However, I don’t think I need the validation of being able to stay with the bunch so it will be better for me to attack and risk my placing than to not be aggressive at all. Hats off to Bill Krause for his breakaway effort and Tak and Jaxson for their strong finishes, and thanks to Phil Shama and the rest of the Shama crew for helping me with everything!

The final bunch sprint – Charles Holsen takes the win. Photo by Rouse Bicycles.

UPDATE: Some news since I last posted – I’d like to congratulate Bill Fiser for finishing 5th in the Road Race and earning enough points for his Cat. 2 upgrade!

Posted in: Cycling, Logs

No. 34: Brute-Force Calculation Project – Password Cracking and Prevention

25 June, 2011 12:52 AM / 2 Comments / Gene Dan

Hi everyone!

It’s been a very long time since I last updated and I have so much to write about – race reports, employment, learning math and computers, and so on and so forth, but I need to keep it short since I have to wake up early tomorrow morning. So, today I’ll be writing about a project that I’ve been working on – brute-force password cracking to help me learn more about permutations and combinations, recursion, efficiency, and possibly multithreading later on. Of course, the most important issue here is cybersecurity and how to prevent attacks.

Let me stress that cybersecurity awareness is an extremely important issue in our day and age and when you have your money, identity, and livelihood entrusted to computers, you need to know how people can access your information and how to reduce the likelihood of attacks or prevent them all together. So, I’m going to give a basic demonstration on one of the most basic methods of password cracking – brute force calculation.

Brute-force cracking is a method by which the computer attempts to crack a password by using every possible combination of passwords until it finds a match. The time it takes to crack a password depends on the length of the password and the speed of the computer. The longer the password, the longer it takes to crack a password, and the more powerful the computer, the faster it can crack the password. The following picture shows how quickly a slow program that I wrote (in the computing world) – in Microsoft Excel – can crack a 4-digit password with a set of 94 printable ASCII characters (click to enlarge):

For 10 trials, it took Excel an average of 14 seconds to break each password.

As you can see, it took an average of 14 seconds for Excel to crack each password – and these aren’t your typical “dumb” passwords either. Combinations like “$HSp,” “DXxg,” and “<9N” extended out to 8 or more characters would be impossible for a human to guess and would be considered “good” by today’s standards. With brute-force calculation human creativity with respect to password creation doesn’t matter – since the computer checks all the combinations, theoretically, given enough time it will surely find with 100% probability, the password.

Luckily, the most powerful tool we humans have against this sort of attack is password length. From a library of 94 printable ASCII characters, each additional character in a password will make the computer work 94 times longer. For instance, it took about 0.005 seconds to crack a password of length 1, 0.07 seconds to crack a password of length 2, 1 second to crack a password of length 3, 14 seconds for 4, 196 seconds for 5, and so on:

The time it takes for Excel to find a match exhibits exponential growth.

As you can see, a password of length 12 will take about 700 years for my computer to solve, not including the time it takes to simulate keystrokes and button clicks, navigate dialog boxes, and so on. The simple solution? Make your password long! A long password means most people will not bother to use this method given current technological constraints. Of course, this presents a much bigger problem when we’re talking about governments, who control supercomputers that are much, much faster than what we can buy in the store. In this case, simple passwords won’t cut it.

Now the exciting part! I know you are all dying to see the code, so here it is in all its glory. It’s remarkably simple, and only takes up about 65 lines of code in three modules. Here’s the first one:

[sourcecode]
Option Explicit

Sub test(compstring As String, pstring As String, places As Long, attempts As Double, matchfound As Range)

If matchfound = True Then Exit Sub

Dim x As Integer, breaker As String

For x = 33 To 126 ‘ASCII character codes 33 to 126
breaker = pstring & Chr(x)
If places > 1 Then Call test(compstring, breaker, places – 1, attempts, matchfound)
attempts = attempts + 1
If compstring = breaker Then
matchfound.Offset(0, -1).Value = attempts
matchfound.Value = "True"
Exit Sub
End If
Next x

End Sub
[/sourcecode]

This module is the heart of the program. What it does is it takes five arguments, the first of which is the original, randomly generated password. Of course in the real world we wouldn’t actually know the password, so this, and the code taking action upon the values passed by this variable, will probably deal with pressing the enter button and seeing if we gain access. Anyway, the second argument is the comparison string used to break the password. The third argument specifies the length of the comparison string, the fourth argument keeps track of the number of attempts, and the fifth argument is a range that refers to a boolean telling us if we’ve successfully reached our goal.

Now, in the real world we wouldn’t know the length of the password, so I had to create a procedure that would automatically increase the length of the comparison string if a match wasn’t found by the end of all the iterations for the current length. At first I tried using loops, but I found that it was much easier to conceptualize a recursive procedure than a looping procedure. I think loops tend to be more efficient, but recursive functions may be a lot easier to read and I think in this case it gives the reader a better understanding of what is going on. When the procedure runs out of combinations of a given length, it calls itself, incrementing the places argument by one to increment the length of the comparison string.

The other modules are higher level modules that control this procedure. They aren’t as exciting, but here’s the second one:

[sourcecode]

Sub main(anchor As Range, digits As Long)

Dim password As String, truthrange As Range
Dim m As Long, bdigits As Long
Dim exectime As Single
Dim exectime2 As Date

exectime = Timer
exectime2 = Now()
bdigits = 1
password = ""

For m = 1 To digits
password = password & Chr(WorksheetFunction.RandBetween(33, 126))
Next m

anchor.Value = "’" & password
Set truthrange = anchor.Offset(0, 2)
truthrange.Value = "False"

Do Until truthrange.Value = True
Call test(password, "", bdigits, 0, truthrange)
bdigits = bdigits + 1
Loop

anchor.Offset(0, 3).Value = Format(Now() – exectime2, "hh:mm:ss")
anchor.Offset(0, 4).Value = Format(Timer – exectime, "00.00000")

End Sub

[/sourcecode]

This module generates a random string which we designate as our password, feeds it into the first module and keeps track of the execution time. It also contains methods for printing the results on the screen. Here’s the third module:

[sourcecode]

Sub macromain()

Dim i As Integer, trials As Integer, digits As Long

Application.ScreenUpdating = False
Application.Calculation = xlCalculationManual

Intersect(Sheets("sheet1").UsedRange, Range("A2:E1048576")).ClearContents

trials = Range("TRIALS")
digits = Range("Digits")

For i = 2 To trials + 1
Call main(Range("A" & i), digits)
Next i

Application.ScreenUpdating = True
Application.Calculation = xlCalculationAutomatic

End Sub

[/sourcecode]

This third module takes user input found on the spreadsheet page indicating the desired number of trials and password length, and feeds this information into the second module. Right now it runs pretty slow and is only programmed to run on one core. My computer at home has three cores and if I can get them to calculate combinations starting from different places in the ranges of ASCII character codes (different places in the range 33 to 126), I can get it to run three times as fast, in my opinion. But that will be for the distant future. One of the more immediate goals I can achieve is GUI programming with keyboard stroke and button clicking simulation to emulate how a human navigates password dialog and text boxes.

And that’s it! What lesson did we learn here?

1) Make your passwords long!
2) For administrators, lock users out if they cannot correctly type in the password after 3-5 attempts. This will prevent the computer from trying the millions of combinations necessary.
3) Check your login data to see if anything looks unusual! If you see a login at a time you did not log in, someone may have taken your data.
4) Always, always use different passwords for different accounts, and don’t reuse your passwords. This will require the thugs to run a new brute force for every account, or find another solution elsewhere.
5) If you have time, spend it on learning how to secure your information. You won’t regret it!

Thanks for reading!

Posted in: Logs

No. 33 Memorial Park Criterium: Race Report

20 January, 2011 4:01 AM / 2 Comments / Gene Dan

Hey everyone,

I’ve got a long overdue report of a race that happened last August, called Memorial Park Criterium. This was just one particular iteration of the Memorial Park Criterium Series, which happens every summer. Unfortunately, I did not know about the series until my friend Ken Day wrote in his blog about his participation…and crash. Anyway, over the summer I’ve been riding with a club called the Space City Cycling Club, which leaves at Bike Barn every weekend at around 7:00 – 7:30 AM for about 60 miles around Alvin and San Jacinto. They have 4 groups based on speed, 14mph, 17mph, 21mph and 24mph. I started with the 14mph group and quickly moved up to the 21mph group where I did the majority of my pack riding for the latter half of 2010. After a while, I decided to ride with the 24 group but I’ve been getting dropped a lot since they tend to go past 34mph at times, speeds at which I cannot hold tempo for long periods of time…yet. In addition to riding with the club, I’ve been doing my own speed work called interval training, which involves doing alternating efforts of hard/easy riding. Intervals help improve the power which you can produce at lactate threshold and help you get accustomed to the high-intensity of racing. Many people who are unfamiliar with cycling don’t realize that racing involves a series of sharp accelerations and cool downs – unlike the steady tempo that may seem intuitive to a novice. Thus, doing easy/hard alternating efforts helps one train like they race. With respect to racing, I had taken a break from racing for over two months, and I was ready to get back into competition, hoping that all my work paid off. Side note – You will notice in the photos that I am riding a new bicycle. I bought one of the team bikes before I graduated and this is the first race at which I rode it.

Registration

 

Before the race, I had just spent about a week in Chicago so I only had about a week after I got home to train for the race. Thus, I wasn’t exactly sure of myself if I would be able to perform well, but since I had performed somewhat poorly in the last handful of races my expectations were low for the race, “stay in contact for 15 minutes, that’s all I’m asking. If you can do more then do it.” Remember, crit racing is very short, only 25-60 minutes but the speeds are very high, and often average higher than 25 mph, even for very technical courses, so you’re more or less at lactate threshold the whole time. On the day of the race, I had just passed my second actuarial examination so I was in good spirits. My dad and I drove to Memorial Park that afternoon and I did the usual routine – unpack, prepare my bike, register, and warm up.

Warming up before the race

I did a few warm up laps and a couple of high-intensity efforts to gauge the corners of the course. In my opinion, they weren’t bad at all. There were no U-turns, unlike the Driveway, and the roads were not too cracked, though they were not smooth like that of the Driveway. I felt like I wouldn’t have nearly as much fear cornering as I would have had at the Driveway. After the warm up, the Cat 5 racers lined up. I saw one rider wearing a regular t-shirt and jeans shorts and I was wondering if he was half-joking. I didn’t see him again after we started so I was assuming he was new to the race. Anyway, after we were all sizing each other up for the few awkward minutes of waiting, the race officials blew the whistle and we were off.

Rounding the last corner before the next lap – the big guy gave me a good draft

Immediately, the speeds kicked up to about 24mph, but I was getting a good draft off the people in front of me so I wasn’t bothered at all. I continued to use my tactic at the Driveway of mimicking exactly how the rider in front of me cornered, so I wouldn’t lose my mind when we went through the corners fast. After a few minutes we started seeing a few attacks off the front but none of them went anywhere. About a couple of laps later, perhaps the 8th minute or so, the person in front of me bolted off of the pack and I followed him – soon we formed a 4 man breakaway but that lasted only a few minutes. The race continued in a similar fashion, with people jumping off the front and getting reeled in. At one point my fear of cornering got the better of me and I accidentally cut someone off – the people behind me yelled at me, so I was a little started but I knew they yelled for good reason – for the safety of all the riders involved. I heeded their criticism and made an effort to stay steady the rest of the race.

Rounding the corner, again

When I finally reached the 15-minute mark, still in contact with the pack, I knew I had reached my goal, so I tried to stay with the group for the remainder of the race. I was doing remarkably well, staying near 8th position for most of the race. At the final lap one of the riders decided to put in an attack and I followed him. Soon, I passed him in the front and I was leading the race at the final lap! It felt incredible, I never thought I would be in such a good position at this point in my training. However, near the last 300m of the race, I ran out of steam and the tempo picked up for a sprint finish – I wasn’t able to compete in the sprint but I stayed with the pack until the end, my first pack finish in a race since Tunis-Roubaix, my first race.

Following the attack!

First, the bad news. Of course, I didn’t win. I went too early and had I not attacked at the end I would have had enough energy to contest the sprint. Then again, it was probably better for me to at least try to attack so I could gain the experience of doing so, since, after all, it was just a minor criterium race. Second, I was too apprehensive in the corners, still. I had improved, but it’s still not at the level where I feel that others can trust me with my handling skills, so I will continue to work on that. Otherwise, everything else went better than expected, I had made my goal and exceeded it, and I knew that my hard work and interval training was paying off, and that I was moving in the right direction.

Leading the race at the final lap

Posted in: Cycling, Logs

No. 32: Decimal to Binary Conversions

14 January, 2011 2:53 AM / Leave a Comment / Gene Dan

Hey everyone,

Today I thought of a small coding exercise for me to do to work on algorithm building – I decided to write a program that converts positive decimal numbers to binary numbers. I knew that I could probably find plenty of examples on the web of this algorithm, but I decided to find out for myself how the conversion worked before looking for any help. Anyhow, one method of algorithm discovery involves the application of that algorithm to a specific example known to be true, and then using that example to pick apart the steps. What I mean is that many of us use algorithms every day in order to solve problems without realizing it or understanding it. For instance, most of you have probably used the division algorithm daily ever since you learned it in kindergarten – for instance, to divide 7 by 2 we subtract the product of 3 and 2 from 7 to obtain the remainder 1. Thus, 7 divided by 2 equals 3 remainder 1. However, how do we know that this algorithm works every single time for every pair of integers? Fortunately prior math enthusiasts have given us a logically rigorous explanation. Looks more complicated when printed, right?

Now, let’s examine how to find the binary value of the integer 27. First, let me give a brief description on how binary values work. In the binary system, every digit of a number is represented by either 1 or 0, in contrast to our common base-10 system, or decimal system, in which each digit may be represented by 0,1,2,3,4,5,6,7,8, or 9. For instance 1 in base-10 is 1 in base-2, 2 in base-10 is 2 in base-2, 3 in base-10 is 11 in base-2, 4 in base-10 is 100 in base-2, and so on, and so forth. In base-2, 10 is twice as much as 1, 100 is twice as much as 10, 1000 is twice as much as 100, and in this manner each digit represents a unit that is twice as large as the digit to the right of it. Check out the link on the binary system to learn more.

Let’s go back to 27. You could try counting in binary (1, 10, 11, 100, 101, …) but that would take too long and would be cumbersome to program. An alternative method we could try is to break up the number 27 into different binary unit values (1000’s, 100’s, 10’s, 1’s), add them up and obtain the final binary representation. However, how many digits would the resulting binary number be? We can’t deduce the answer simply by staring at 27, so let’s try to divide by 2 and see what happens. After dividing 27 by 2, we get 13 remainder 1. What happens if we divide 13 by 2? We get 6 remainder 1. Dividing 6 by 2 gives us 3, and dividing 3 by 2 gives us 1 remainder 1. Note that we applied the division algorithm 4 times. It just so happens that 2^4 = 16, and that 10^4 = 10000. We know that 10000 in binary is equal to 16 in decimal because 10 in binary is equal to 2 in decimal and 10x10x10x10 in binary is equal to 2x2x2x2 in decimal. Thus, we know that 16 out of our original 27 consists of 10000 in binary. What about the other 27 – 16 = 11? We then take 11 and divide that by 2 to obtain 5 remainder 1, divide 5 by 2 to obtain 2 remainder 1, and divide by 2 to obtain 1. In this next round of divisions we have applied division by 2, 3 times. Thus 10x10x10 = 1000 in binary, which is equal to 8 in decimal. Now we have 11-8 = 3 remaining to consider. We divide 3 by 2 to obtain 1 remainder 1. We have applied division by 2 once, so 10 in binary is equal to 2 in decimal. Now we only have 3-2 = 1 remaining and 1 in decimal is equal to 1 in binary. So, we know that 16 + 8 + 2 + 1 in decimal is equal to 10000 + 1000 + 10 + 1 = 11011 in binary…success!

I must stress that this does not prove that the algorithm works – it has only worked in this one particular instance. However, this instance has shed some light, at least for now until I actually gain the knowledge to do a mathematically rigorous proof – which won’t be coming in a long time!

Using this example as a guide I wrote down some code:

[sourcecode language=”css”]
//Decimal to Binary Conversion

#include <iostream>
#include <cmath>
using namespace std;

const int base = 2;
long long baseconv(long);

int main()
{
long long inputval;

cout << "Enter an integer: _b";
cin >> inputval;
cout << inputval << " is " << baseconv(inputval) << " in binary!" << endl;
return 0;
}

long long baseconv(long input)
{
long long baseconv;
long long updater;
long long dival;
long digitcount;
baseconv = 0;

while (input > base – 1)
{
digitcount = 0;
dival = input;
while (dival > base – 1)
{
dival = dival / 2;
digitcount = digitcount + 1;
}
updater = pow(base, digitcount);
baseconv = baseconv + (pow(10,digitcount));
input = input – updater;
}
baseconv = baseconv + input;
return baseconv;
}

[/sourcecode]

Here’s an example of the output:

I’m running out of time so I don’t want to go into every single detail over this program, but in a nutshell, the program splits the input integer into separate binary parts, then adds the binary parts together in order to obtain the result. Unfortunately, the memory limitations of c++ do not allow me to convert very large integers, such as 1234123412341234. See what happens when I try to convert this value:

Also, the program does not work with negative values, so those will be two things that I will work on in the near future. I also spent the time to port the program into VBA, and I changed it to do conversions from base-10 to any base the user chooses:

[sourcecode language=”css”]
Function BASECONV(inputval As Long, base As Integer) As Variant

Dim dival As Long
Dim digitcount As Integer
Dim updater As Long

BASECONV = 0

Do While (inputval > base – 1)
digitcount = 0
dival = inputval
Do While (dival > base – 1)
dival = dival base
digitcount = digitcount + 1
Loop
updater = base ^ digitcount
BASECONV = BASECONV + (10 ^ digitcount)
inputval = inputval – updater
Loop

BASECONV = BASECONV + inputval

End Function
[/sourcecode]

Notice how much more efficient the code is! That’s because VBA is at a much higher level than C++, so there are a lot more built-in functions that do the work for you. Here’s an example of the output:

Posted in: Logs

Post Navigation

« Previous 1 … 22 23 24 25 26 … 30 Next »

Archives

  • August 2025
  • July 2025
  • September 2023
  • February 2023
  • January 2023
  • October 2022
  • March 2022
  • February 2022
  • December 2021
  • July 2020
  • June 2020
  • May 2020
  • May 2019
  • April 2019
  • November 2018
  • September 2018
  • August 2018
  • December 2017
  • July 2017
  • March 2017
  • November 2016
  • December 2014
  • November 2014
  • October 2014
  • August 2014
  • July 2014
  • June 2014
  • February 2014
  • December 2013
  • October 2013
  • August 2013
  • July 2013
  • June 2013
  • March 2013
  • January 2013
  • November 2012
  • October 2012
  • September 2012
  • August 2012
  • July 2012
  • June 2012
  • May 2012
  • April 2012
  • March 2012
  • February 2012
  • January 2012
  • December 2011
  • September 2011
  • August 2011
  • July 2011
  • June 2011
  • January 2011
  • December 2010
  • October 2010
  • September 2010
  • August 2010
  • June 2010
  • May 2010
  • April 2010
  • March 2010
  • September 2009
  • August 2009
  • May 2009
  • December 2008

Categories

  • Actuarial
  • Cycling
  • FASLR
  • Logs
  • Mathematics
  • MIES
  • Music
  • Uncategorized

Links

Cyclingnews
Jason Lee
Knitted Together
Megan Turley
Shama Cycles
Shama Cycles Blog
South Central Collegiate Cycling Conference
Texas Bicycle Racing Association
Texbiker.net
Tiffany Chan
USA Cycling
VeloNews

Texas Cycling

Cameron Lindsay
Jacob Dodson
Ken Day
Texas Cycling
Texas Cycling Blog
Whitney Schultz
© Copyright 2026 - Gene Dan's Blog
Infinity Theme by DesignCoral / WordPress