Binary Kata

There are only 10 types of people in the world:

  • Those who understand binary
  • Those who don’t

How is your binary today?

If you want to become one of the former group, here is a coding kata for you. I derived this from a tester at a client who is currently pursuing his Computer Science degree. While he was asking for help on an exercise, we came up with the idea, that this exercise would be a pleasant coding kata.

The kata itself is easy. Write a program which takes any floating point number and converts it into a string representation of the bits in a floating point format. As a suggestion you may want to start with the single-precision format where you have one bit for the sign, 8 bits for the exponent, and 23 bits for the fraction. If you seek some more challenge, go for double- or extended-precision.

Here are some values that you might want to consider:

  • 0.0
  • 123.456
  • Pi
  • 1.9999999
  • -2.5521175E38

If you seek some help on how to convert these numbers, here is a web-based converter using a Java Applet.

  • Print
  • Twitter
  • LinkedIn
  • Google Bookmarks

Leave a Reply

Your email address will not be published. Required fields are marked *