base-conversion

Base conversion of arbitrary sized numbers (PHP)

穿精又带淫゛_ 提交于 2019-12-18 17:27:15
问题 I have a long "binary string" like the output of PHPs pack function. How can I convert this value to base62 (0-9a-zA-Z)? The built in maths functions overflow with such long inputs, and BCmath doesn't have a base_convert function, or anything that specific. I would also need a matching "pack base62" function. 回答1: I think there is a misunderstanding behind this question. Base conversion and encoding/decoding are different . The output of base64_encode(...) is not a large base64-number. It's a

Computing the Factoradic Rank of a Permutation (N choose K)

可紊 提交于 2019-12-18 05:12:50
问题 I've recently learnt about CNS and FNS, and since they look so elegant to me, I decided to try and implement methods to generate combinations and permutations using those techniques. I finished my method to convert from n choose k combinations to a CSN rank and vice-versa but I'm banging my head against the wall trying to do the same with n choose k (unique) permutations. Thanks to @Joshua I got the unranking (FNS to permutation) method working: function Pr_Unrank($n, $k, $rank) { // rank

Converting binary string to a hexadecimal string JAVA

我怕爱的太早我们不能终老 提交于 2019-12-18 04:43:11
问题 I want to convert my binary(which is in string) to hexadecimal string also, this is just a program fragment since this program is just a part of another bigger program: //the variable name of the binary string is: "binary" int digitNumber = 1; int sum = 0; int test = binary.length()%4; if(test!=0) { binary = padLeft(binary, test); } for(int i = 0; i < binary.length(); i++){ if(digitNumber == 1) sum+=Integer.parseInt(binary.charAt(i) + "")*8; else if(digitNumber == 2) sum+=Integer.parseInt

algorithm to convert a number in an unknown base to the equivalent base 10 number [duplicate]

南楼画角 提交于 2019-12-14 04:24:02
问题 This question already has an answer here : Closed 7 years ago . Possible Duplicate: Efficient algorithm for conversion between numeral system Given an integer, write a program that converts the given number to a number (in base 10). Hint - The given number could be in any base, but the base is unknown. 回答1: That can't be done; without knowing the source base the number is ambiguous. 10 in base n translates to n in base 10 ; there are infinite possibilities 回答2: I'm assuming by 'unknown' you

Hex to Dec conversion with printf in sh fail for more than 16 digits

﹥>﹥吖頭↗ 提交于 2019-12-13 23:46:10
问题 I only have shell available no bash, Perl, python etc. Using printf small numbers work: root@DD-WRT:/jffs# printf "%d\n", 0x15a 346 But large numbers fail. root@DD-WRT:/jffs# printf "%d\n", 0x15abc12345afda325 sh: invalid number '0x15abc12345afda325' 0 Also is it possible to perform hexadecimal arithmetic for example Module using shell ? 回答1: What shell is this? On Linux I see: $ bash -c 'echo $((0x15abc12345afda325))' 6538120775109288741 wrong $ dash -c 'echo $((0x15abc12345afda325))'

Convert Integer to Generic Base Matlab

笑着哭i 提交于 2019-12-12 18:33:51
问题 I'm trying to convert a base-10 integer k into a base-q integer, but not in the standard way. Firstly, I'd like my result to be a vectors (or a string 'a,b,c,...' so that it can be converted to a vector, but not 'abc...'). Most importantly, I'd like each 'digit' to be in base-10. As an example, suppose I have the number 23 (in base-10) and I want to convert it to base-12. This would be 1B in the standard 1,...,9,A,B notation; however, I want it to come out as [1, 11]. I'm only interested in

PHP - How to base_convert() up to base 62

好久不见. 提交于 2019-12-12 07:12:29
问题 I need a base_convert() function that works from base 2 up to base 62 but I'm missing the math I need to use, I know that due to the limitations of PHP I need to make use of bcmath, which is fine. Functions like these convert a number to and from base 10 to another base up to 62, but I want to implement the same functionality of base_convert() , e.g.: a only one function that can convert between arbitrary bases. I've found a function that seems to do this, but it gives me the feeling of

Base converter binary to octal

狂风中的少年 提交于 2019-12-12 00:47:16
问题 I'm writing a base converter because I have a test soon and I need to convert a binary number in 3 different bases: octal, decimal and hexadecimal. I've already written the code that convert a binary string into decimal and hexadecimal. function bintodec(Value:string;dec:TEdit;hexadec:TEdit): Integer; var //dec and hexadec are the TEdits where I will put the result i, iValueSize: Integer; Edit2,f:TEdit; begin Result := 0; iValueSize := Length(Value); for i := iValueSize downto 1 do begin if

Optimizing Base Conversion Loop

﹥>﹥吖頭↗ 提交于 2019-12-10 17:04:26
问题 So, for my Cryptography Library, I have a base converter that I use quite often. It's not the most efficient thing in the world, but it works quite well for all ranges of input. The bulk of the work is done by the callback loop: $callback = function($source, $src, $dst) { $div = array(); $remainder = 0; foreach ($source as $n) { $e = floor(($n + $remainder * $src) / $dst); $remainder = ($n + $remainder * $src) % $dst; if ($div || $e) { $div[] = $e; } } return array( $div, $remainder ); };

How to convert a string to its Base-10 representation?

ぃ、小莉子 提交于 2019-12-10 15:29:07
问题 Is there any python module that would help me to convert a string into a 64-bit integer? (the maximum length of this string is 8 chars, so it should fit in a long). I would like to avoid having to write my own method. Example: Input String Hex result (Base-10 Integer) 'Y' 59 89 'YZ' 59 5a 22874 ... 回答1: This is a job for struct: >>> s = 'YZ' >>> struct.unpack('>Q', '\x00' * (8 - len(s)) + s) (22874,) Or a bit trickier: >>> int(s.encode('hex'), 16) 22874 回答2: I don't think there's a built-in