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
4
votes
4 answers

Decimal-to-binary conversion

I want to convert decimal numbers to binary numbers. I want to store them in an array. First I need to create an array that has a certain length so that I can store the binary numbers. After that I perform the conversion, here is how I do it: public…
DarkLeafyGreen
  • 69,338
  • 131
  • 383
  • 601
4
votes
3 answers

How to convert decimal number to Base58 in a shell script

myNumber=$(date +%s) # big number in decimal myNumberInB58=$(toBase58 $myNumber) toBase58() { # } What is the most elegant and/or concise way to encode an integer in Base58?
Elifarley
  • 1,310
  • 3
  • 16
  • 23
4
votes
4 answers

Converting a repeating binary number to decimal (express as a series?)

Given a binary number that repeats, for example 0.(0011) or 0.0(101), how would one go about converting it to decimal? What I've been able to dig up so far is the simple method for converting a terminating binary number to decimal, as…
user257686
4
votes
2 answers

Base 10 to base 2,8,16 conversion in java

I'm in this Object Oriented class, but I just don't know how to do this. I know basic fundamentals but nothing like this. I am asked to create a program that converts #'s base 10 to base 2, base 8,and base 16. Then, after we are asked to convert it…
Justin Park
  • 99
  • 1
  • 1
  • 4
4
votes
2 answers

How to convert string to int with different bases?

I want to convert string to int but the conversion has to consider the prefixes 0x or 0 if any and consider the input as hex or oct respectively. Using istringstream, you need to explicitly specify the base. Is there any way than explicitly coding…
balki
  • 26,394
  • 30
  • 105
  • 151
4
votes
1 answer

Java's buit-in libraries (or 3rd party code) to do base-conversions

Is there any built-in libraries (or any good 3rd party code) that support converting a number from any arbitrary base A to another base B? Thanks,
One Two Three
  • 22,327
  • 24
  • 73
  • 114
3
votes
2 answers

PHP conversions between binary, octal, decimal and hexadecimal with floating number

I would like to convert floating numbers (eg. 152.35964) between binary, octal, decimal and hexadecimal numbers. I googled but I didn't found anything relative to what I want. All that I have found was in documentation but these functions (bindec(),…
tzortzik
  • 4,993
  • 9
  • 57
  • 88
3
votes
2 answers

How to convert Decimal (Base 10) to Fractional bases (i.e. Base 3/2) in Javascript

I have found many resources talking about base conversion algorithms and using built in Javascript functions to convert decimal to binary or hex, however I can't find any resources on how to convert to any fractional bases like base 3/2 for…
Wowkster
  • 197
  • 3
  • 9
3
votes
1 answer

Conversion between Zeckendorf and Golden Ratio Base

Zeckendorf and Golden Ratio Base are clearly closely related, but still it seems tricky to convert from one to the other. I know that there is work by Frougny and Sakarovitch on this, but I haven't fully understood this. One problem is that Golden…
Dale Gerdemann
  • 739
  • 5
  • 7
3
votes
2 answers

A single function to convert decimal values to binary, hexadecimal and octal does not convert to binary

I am trying to build a standard function to convert any decimal value to its octal, hexadecimal and binary equivalent but it doesn't work for binary for some reason. I tried putting extra precautions into the conditional statement to check for base…
Onur-Andros Ozbek
  • 2,998
  • 2
  • 29
  • 78
3
votes
2 answers

Conversion of base 10 to base 6

I tried to convert a base 10 number to base 6 in C, but my code didn't pass 2 hidden test cases. I can't find any logical error in it. Could you? //convert base 10 to base 6 #include int main() { int num, rem = 0, i = 1, res = 0; …
Viky
  • 63
  • 2
  • 7
3
votes
6 answers

C code for converting decimal to any base (from 2 to 36)

I have just recently started learning C. I wrote a very short program that converts between decimal and binary. I wanted to try and write a code that converts between decimal and any base (up until 36). However, my code just prints out…
Gulim Daulbekova
  • 45
  • 1
  • 2
  • 7
3
votes
4 answers

How can I output a number as a string of bits in C#?

In C#, how can I output a number as binary to the console? For example, if I have a uint with the value of 20, how can I print to the console: 00010100 (which is 20 in binary)?
James
3
votes
1 answer

convert β-bit integer to array of digits using only O(lg β) multiplications and divisions

(edit: the question that my question has been flagged a duplicate of was already linked in my original post, even before the flagging, and I did not consider it sufficient to answer my specific question, why was how to get a certain complexity…
xdavidliu
  • 2,411
  • 14
  • 33
3
votes
3 answers

Convert Base 16 (Hexadecimal) to Base 36 String in C

In C, what's an efficient way to convert a 64 character hexadecimal number (as a string) into a base 36 string? I mean, is it as easy as combining a few GLIB2 functions (on Linux), or Standard Library functions? Or, do I have to do it all custom?
Volomike
  • 23,743
  • 21
  • 113
  • 209
1 2
3
13 14