Questions tagged [base-conversion]

Base conversion is the process of changing the base of the textual representation of a number to another base. For example, "1010" in binary to "10" in decimal is a base conversion.

Base conversion is the process of changing the base of the textual representation of a number to another base. For example, 1010 in binary to 10 in decimal is a base conversion.

198 questions
8
votes
3 answers

Converting Numbers from Base 10 to Base 60

Recently, I was reading about the Ancient Babylonian Civilization that used a number system with base 60 instead of base 10. Even with this number system at base 60, they were still able to approximate the square root of 2 — and that too, thousands…
stats_noob
  • 5,401
  • 4
  • 27
  • 83
8
votes
3 answers

base_convert in .NET

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…
Dinah
  • 52,922
  • 30
  • 133
  • 149
8
votes
7 answers

PHP - Generate an 8 character hash from an integer

Is there a way to take any number, from say, 1 to 40000 and generate an 8 character hash? I was thinking of using base_convert but couldn't figure out a way to force it to be an 8 character hash. Any help would be appreciated!
doc
  • 115
  • 1
  • 1
  • 7
7
votes
2 answers

Unlimited-size base conversion?

I'm trying to implement a BigInt type in JavaScript using an array of integers. For now each one has an upper-bound of 256. I've finished implementing all integer operations, but I can't figure out how to convert the BigInt to its string…
Ry-
  • 218,210
  • 55
  • 464
  • 476
7
votes
2 answers

Calculating the negabinary representation of a given number without loops

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) ^…
Misha Moroshko
  • 166,356
  • 226
  • 505
  • 746
6
votes
3 answers

Convert a 74-bit integer to base 31

To generate a UFI number, I use a bitset of size 74. To perform step 2 of UFI generation, I need to convert this number: 9 444 732 987 799 592 368…
thibsc
  • 3,747
  • 2
  • 18
  • 38
6
votes
3 answers

Converting a octal String to Decimal in Objective-C?

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,…
Keoros
  • 1,337
  • 2
  • 13
  • 23
5
votes
1 answer

base_convert and negative numbers

The base_convert() function doesn't seem to preserve the sign. For example: var_dump (base_convert ('-100', 10, 10)); The output of this is 100 Is there a way of converting bases without losing the sign?
GordonM
  • 31,179
  • 15
  • 87
  • 129
5
votes
4 answers

Golang number base conversion

I was wondering, how do you convert a base10 number from one base to another without usage of strconv in Golang ? Could you please give me some advice ?
Elmor
  • 4,775
  • 6
  • 38
  • 70
5
votes
2 answers

Base conversion of arbitrary sized numbers (PHP)

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…
tryexcept
5
votes
4 answers

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

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 …
E.Z.
  • 6,393
  • 11
  • 42
  • 69
4
votes
2 answers

Converting decimal to binary

I want to convert decimal number in binary number. I'm using this method: - (NSMutableString*)intStringToBinary:(long long)element{ NSMutableString *str = [[NSMutableString alloc] initWithString:@""]; for(NSInteger numberCopy = element;…
V-JAY
  • 81
  • 4
4
votes
3 answers

How to convert decimal (base 10) numbers to ternary (base 3)

I was wondering if there is a way to convert decimal numbers to ternary, given that there is a function intToBits for converting to binary. I actually need to convert a character string like > S0 <- c("Hello Stac") to base 3. I thought to first…
4
votes
3 answers

Optimizing Base Conversion Loop

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 =…
ircmaxell
  • 163,128
  • 34
  • 264
  • 314
4
votes
2 answers

Convert decimal to balanced Heptavintimal

I'm trying to make a function to convert decimal to balanced Heptavintimal (0123456789ABCDEFGHKMNPRTVXZ) where 0 represent -13, D : 0 and Z 13 I have tried this but some cases are not working properly: static const std::string HEPT_CHARS =…
Jeremy Talus
  • 125
  • 2
  • 11
1
2
3
13 14