google apps script - How do I convert a string into a bitmask in javascript? -


Now, it is very easy when numbers are small, but numbers like "9223372036854775807" are too large for parseInt ().

I'm not sure how to do this in the Google Docs Script Editor, which does not allow external classes.

Here you can go, used this script somewhere and it starts working. The idea behind this is that it divides the string into an 8-character quantity, and calculates 2 of the chak, then the segment is described above and the result of division is 2.

By dividing by 2 - It easily calculates the result.

  var maxIntSize = 8; Function divide2 (number, addup, depth) {var result = ""; Var partLength = Math.min (number, length, maximuminstances); Var part = number.substring (0, partLength); Var partNum = parseInt (part, 10); Var partAdd = (addup == 0)? 0: (5 * Math.p. (10, Bhagalanth-1)); Var partRes = Math.floor (partNum / 2) + partAdd; Var partRem = partNum% 2; Results = Results + Bhagaris; If (depth> gt; 0) {for (var i = result.length; i & lt; partLength; i ++) {result = "0" + result; }} Var nextPart = number.substring (partLength, number.length); If (partLength & lt; number.length) {var res = divide2 (Next section, partRem, Depth + 1); Results = result + res.result; Res.result = Result; Return ridge; } Else {var res = {result: result, remaining: partRem}; Return ridge; }} Function to Binary (number) {var out = ""; Whereas (number.length> gt; 1 = number! = "0") {var res = divide2 (number, 0,0); Out = "" + res.remainder + out; Number = res.result; } Exit; } Var testNum = "12312312312112312312312312312312312312312312312312312312312312312312312312312312312312312312123"; Document.write ("bin (" + testNum + ") =" + toBinary ("+ testNum +" 
");

It is necessary to calculate the rapid splitting from 2. This script works very fast for a very large number.


Comments