daily pastebin goal
24%
SHARE
TWEET

Untitled

a guest Jan 23rd, 2019 52 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. Example octal number = 147
  2.  
  3. Method one: From left to right.
  4. Step 1: First digit is one. Take that times 8 plus 4. Got 12.
  5. Step 2: Take 12 times 8 + 7. Got 103, and 103 is the answer.
  6.    
  7. Method 2, bitshift:
  8. Octal Number: 147.
  9.  
  10. Step 1: 1 = 1(bin) = Shift << 3 = 1000(result value)
  11. Step 2: 4 = 100(bin) + 1000(result value) = 1100(result value)
  12. Step 3: 1100(result value) Shift << 3 = 1100000
  13. Step 4: 7 = 111(bin) + 1100000(result value) = 1100111
  14. Step 5: 1100111 binary is 103 decimal.
  15.    
  16. for ( int i = 0; i < length; i++ ){
  17.      c = (str.charAt(i) ^ 48);
  18.      if ( c > 7 ) return 0;
  19.      out = (out << 3) + c;
  20.  }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top