Algorithm of 575 - Skew Binary

Problem Description Link

This is a simple problem . only convert skew value to decimal value.
You can follow this stapes:
1. Get input string for skew value.
    (N.B: Input is string because input value range may greater than any type of value ie, int,... But
          result range in 2^31-1)
2. determine the length of input value.
3. under for loop i=0 to length-1
       decimalvalue+=(input[i]-48)*(pow(2,length-i)-1);
4. finally print the value of decimalvalue.
ie.
    input=10120
       length=5 so process is
    =1*(2^5-1)+0*(2^4-1)+1*(2^3-1)+2*(2^2-1)+0*(2^1-1)
    =31+0+7+6+0
    = 44
 so 44 is equivalent decimal value.

   
image

No comments:

Post a Comment

Write your comment - Share Knowledge and Experience