base-conversion

Calculating the negabinary representation of a given number without loops

岁酱吖の 提交于 2019-12-29 06:59:08
问题 Could you provide a convincing explanation, or a mathematical proof, to why the following function calculates the negabinary representation of a given number? function quickNegabinary(number) { var mask = 0xAAAAAAAA; return ((number + mask) ^ mask).toString(2); } 回答1: Negabinary notation Negabinary notation uses a radix of -2. This means that, as in every number system with a negative base, every other bit has a negative value: position: ... 7 6 5 4 3 2 1 0 binary: ... 128 64 32 16 8 4 2 1

Convert large hex string to decimal string

ε祈祈猫儿з 提交于 2019-12-29 06:21:11
问题 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

Recursive function to convert between number bases fails at certain numbers

故事扮演 提交于 2019-12-24 10:44:02
问题 I'm trying to a create an algorithm that can convert base 10 numbers into base n numbers, where n is at most 10. However, for some weird reason the following algorithm in C fails at certain critical points for each base. For example, for base 2 and base 3 conversions, all numbers up to and including 1023 and 52,487 work, respectively, but numbers beyond that produce some weird negative result. I can't figure out why this is happening; can anyone help me? #include <stdio.h> #include <stdlib.h>

Generating 5 digit alphanumeric code with predifined characters in sequence

江枫思渺然 提交于 2019-12-24 10:38:02
问题 I would like to generate a membership number consisting of alphanumeric characters, removing i o and l to save confusion when typing. to be done in php (also using Laravel 5.7 if that matters - but i feel this is a php question) If simply using 0-9 the membership number would start at 00001 for the 1st one and the 11th person would have 00011. I would like to use alphanumeric characters from 0-9 + a-z (removing said letters) 0-9 (total 10 characters), abcdefghjkmnpqrstuvwxyz (total 23

Converting a octal String to Decimal in Objective-C?

强颜欢笑 提交于 2019-12-23 09:29:52
问题 I trying to do conversions between Binary, Octal, Decimal and Hexadecimal in Objective-C. I had problems converting Octal to Decimal. I have tried the following: NSString *decString = [NSString stringWithFormat:@"%d", 077]; It works fine, returning 63 as expected, but my Octal value is a NSString. How can I tell the computer that it is a Octal; I know there is a method called "scanHexInt:" which I used to convert Hexadecimal to decimal, but it seems there is no scanOctInt... Any help would be

PL/SQL base conversion without functions

微笑、不失礼 提交于 2019-12-23 02:34:54
问题 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. 回答1: 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

Bash decimal to base 62 conversion

耗尽温柔 提交于 2019-12-22 03:50:45
问题 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

Converting number base

送分小仙女□ 提交于 2019-12-21 01:20:09
问题 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 回答1: 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

How can I convert a number in a string to any base in assembly?

无人久伴 提交于 2019-12-20 04:16:33
问题 How can I convert a number contained in a string from any base to any other base? Bases can be anything i.e.: 2, 16, 10, 4, 8, 9. I'm expecting the user to enter the base number. The user will enter the output base (the base to be converted to). The user will enter the number he wants to convert. Pre thoughts: I will save the input base and the output base in variables. Then I'll save the number he enters in a string (because he could enter any kind of number (hex, binary, base-5..). I'm just

Base conversion of arbitrary sized numbers (PHP)

霸气de小男生 提交于 2019-12-18 17:27:37
问题 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