base-conversion

base_convert in .NET

。_饼干妹妹 提交于 2019-12-09 18:27:36
问题 Does .NET have a native function that is equivalent to PHP's base_convert or will I need to write my own? I want to convert from any base to any other base -- where either the 'to' base or the 'from' base can be any integer 2-36. Example of the PHP function: base_convert($number_to_convert, $from_base, $to_base) // convert 101 from binary to decimal echo base_convert('101', 2, 10); // 5 As noted by Luke in the comments of Jon Skeet's answer: Convert.ToString can't handle conversion to/from

How to convert base64 to base10 in PHP?

不羁岁月 提交于 2019-12-08 06:35:52
问题 I currently convert base10 numbers to base64 in PHP. but I haven't any idea for convert base64 to base10 in php! How can I do it? my algorithm for convert base10 to base64: $rep = array('0','1','2','3','4','5','6','7','8','9','a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z','A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z','-','_'); $new = ""; while ($num>0) { $r = $num % 64; $new .=

PL/SQL base conversion without functions

試著忘記壹切 提交于 2019-12-08 03:53:24
Is there any way to convert decimal to binary, or binary to decimal, in Oracle 10g without having to first define a function? I have limited database access (SELECT only) and all the solutions for this I've found online seem to involve CREATE FUNCTION , which does not work for me. If hexadecimal is good enough, then TO_CHAR and TO_NUMBER can work: SQL> select to_char(31, '0x') from dual; TO_ --- 1f SQL> select to_number('1f', '0x') from dual; TO_NUMBER('1F','0X') -------------------- 31 You may be able to use the RAWTOHEX() and HEXTORAW() functions to make the hex to binary transition as well.

How to convert base64 to base10 in PHP?

旧巷老猫 提交于 2019-12-07 16:30:30
I currently convert base10 numbers to base64 in PHP. but I haven't any idea for convert base64 to base10 in php! How can I do it? my algorithm for convert base10 to base64: $rep = array('0','1','2','3','4','5','6','7','8','9','a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z','A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z','-','_'); $new = ""; while ($num>0) { $r = $num % 64; $new .= $rep[$r]; $num = floor($num/64); } Here is a Javascript way of doing it. Perhaps you can code one for

How to convert a decimal base (10) to a negabinary base (-2)?

怎甘沉沦 提交于 2019-12-05 18:06:14
问题 I want to write a program to convert from decimal to negabinary. I cannot figure out how to convert from decimal to negabinary. I have no idea about how to find the rule and how it works. Example: 7(base10)-->11011(base-2) I just know it is 7 = (-2)^0*1 + (-2)^1*1 + (-2)^2*0 + (-2)^3*1 + (-2)^4*1 . 回答1: The algorithm is described in http://en.wikipedia.org/wiki/Negative_base#Calculation. Basically, you just pick the remainder as the positive base case and make sure the remainder is

Bash decimal to base 62 conversion

点点圈 提交于 2019-12-05 02:41:28
I would like to reverse the operation performed by the following bash command: $ echo $((62#a39qrT)) 9207903953 i.e. convert decimal 9207903953 to base 62 , keeping bash standard of {0..9},{a..z},{A..Z} . I know I can do this by using bc , but I will have to manually convert each character then. For example, I do this currently: BASE62=($(echo {0..9} {a..z} {A..Z})) for i in $(echo "obase=62; 9207903953" | bc) do echo -n ${BASE62[$i]} #Doesn't work if bc's output contains leading zeroes done There must be a way to do this in a less 'hackier' way. Do you know of a way to do this more

Convert a very large number from decimal string to binary representation? [closed]

喜你入骨 提交于 2019-12-05 02:01:37
问题 It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center. Closed 7 years ago . I have a very big number, on the order of a thousand decimal digits, and I have to convert this to its binary representation. The numbers are stored as strings. Since few languages have a basic data type to

base_convert in .NET

元气小坏坏 提交于 2019-12-04 08:26:24
Does .NET have a native function that is equivalent to PHP's base_convert or will I need to write my own? I want to convert from any base to any other base -- where either the 'to' base or the 'from' base can be any integer 2-36. Example of the PHP function: base_convert($number_to_convert, $from_base, $to_base) // convert 101 from binary to decimal echo base_convert('101', 2, 10); // 5 As noted by Luke in the comments of Jon Skeet's answer: Convert.ToString can't handle conversion to/from any arbitrary base, only 2, 8, 10 and 16 Update: Apparently, the answer is: no, there is no native way.

Convert large hex string to decimal string

大城市里の小女人 提交于 2019-12-03 13:46:04
I need to convert a large (too large for the built-in data types) hex string to a string with it's decimal representation. For example: std::string sHex = "07AA17C660F3DD1D2A1B48F1B746C148"; std::string sDec; // should end up with: "10187768649047767717933300899576725832" I'm currently using the c++ BigInt Class which offers a very easy way to achieve this (but is GPL only): BigInt::Vin vbiTemp(sHex, 16); sDec = vbiTemp.toStrDec(); Is there simple way to do this conversion without a 3rd party arithmetic library? Or can you recommend a free (non-GPL) alternative with similar simplicity

Converting number base

岁酱吖の 提交于 2019-12-03 07:30:35
Is there a platform function that will do the following? convertBase :: (Num a, Num b) => Int -> Int -> [a] -> [b] Convert a number from base 'a' to base 'b' where each list item is a digit in the number. for example: convertBase 2 10 [1,1,0,1] = [1, 3] I hope that makes sense, let me know if i can clear anything up Using the digits package from Hackage: import Data.Digits (digits, unDigits) convertBase :: Integral a => a -> a -> [a] -> [a] convertBase from to = digits to . unDigits from You can add a fromIntegral in there if you need the input and output types to be different. Also, the