googles tweet – solved the google way!

Google created an official google account on twitter and announced their arrival on to the micro blogging scene.

The 1st tweet was

I’m 01100110 01100101 01100101 01101100 01101001 01101110 01100111 00100000 01101100 01110101 01100011 01101011 01111001 00001010

This is nothing but a text coded in binary. Since each binary word is 8 characters long, it is most probably written in the extended 8-bit ASCII code. In fact, it can be read with a simple ASCII chart (link)

Most charts like the one above will only provide you with the decimal equivalent for each ascii value. So since out of laziness i decided to code a java program to convert binary into decimal so i can read googles tweet.

The conversion is quite simple. Each position is to be multiplied by increasing powers of two from the right and then these numbers are added together. eg: 1010 = 1 * 8 + 0 * 4 + 1 * 2 + 0 * 1 = 10.

Program :

static double toDecimal (String s)
 {
 int l = s.length();
 int ceq=0;
 double result = 0;
 int i=0,j=0;

 for (i = l-1; i >= 0; i--,j++)
 {
 if (s.charAt(i)=='0')
 { ceq=0; }
 if (s.charAt(i)=='1')
 { ceq=1; }
 result = result + (ceq * Math.pow(2,j));
 System.out.println("result "+result);    
 }

 return result;
 }

So after running the tweet i got

I’m feeling lucky\n

phd012606s

Advertisement

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.