Title: **Binary Equation**

Post by:**fuzzball27** on **Jul 19, 2011, 02:34 am**

Post by:

Is there an algebraic equation that Arduino can run to convert from base 10 to binary form? (and binary to base 10; *algebraic*)

Title: **Re: Binary Equation**

Post by:**retrolefty** on **Jul 19, 2011, 03:00 am**

Post by:

Well the serial print command can told to output a variable in either decimal or binary value so the code must be around inside the core somewhere. ;)

Title: **Re: Binary Equation**

Post by:**Utopia** on **Jul 19, 2011, 07:41 am**

Post by:

Internally, values are usually binary (although you can assume they are anything you want,like ascii, bcd, etc.) So input routines take a decimal number and convert it to binary. Output routines take the binary and output as decimal.

If you want an algorithm for them, it's somewhat like this:

internal to base 10:

take the binary number

divide by 10, saving the remainder (which is a digit of the result) and the result

keep doing that to the result, successively peeling off digits until the result is zero

take this digits and output them in the reverse order you generated them

base 10 to internal:

take the input character, and convert to a digit (0-9)

multiply the internal number by 10,and add this digit

repeat to the internal number for each digit until all the input is 'used up'

If you want an algorithm for them, it's somewhat like this:

internal to base 10:

take the binary number

divide by 10, saving the remainder (which is a digit of the result) and the result

keep doing that to the result, successively peeling off digits until the result is zero

take this digits and output them in the reverse order you generated them

base 10 to internal:

take the input character, and convert to a digit (0-9)

multiply the internal number by 10,and add this digit

repeat to the internal number for each digit until all the input is 'used up'

Title: **Re: Binary Equation**

Post by:**robtillaart** on **Jul 19, 2011, 11:08 am**

Post by:

Quote

Is there an algebraic equation that Arduino can run to convert from base 10 to binary form? (and binary to base 10; algebraic)

What is the datatype of the input and output??

If it was a function how would the prototype of it look like? e.g String(int x, int toBase); ...

Title: **Re: Binary Equation**

Post by:**fuzzball27** on **Jul 19, 2011, 02:00 pm**

Post by:

Let me rephrase: "Is there an algebraic equation to convert between base10 and binary?"

Title: **Re: Binary Equation**

Post by:**JChristensen** on **Jul 19, 2011, 05:46 pm**

Post by:

This is one of those questions that is difficult to answer out of context, which is why folks are answering with more questions. The answer depends on where the base 10 and binary numbers are, and how they are being used, so a little more background would help. I'm not sure about the "algebraic equation" part. Algebra deals with variables and numbers, and the base is largely irrelevant. The algebraic equation a = b + c is valid regardless of the base of the variables.

So I'm not sure there is such a thing as an algebraic equation to do base conversion. But as others pointed out, there certainly are*algorithms* to do base conversion, and some are even built into the Arduino environment.

On the other hand, the internal representation of a number in hardware is always binary. I like to say (usually when the boss is really steamed about something) "It's all just ones and zeroes." Or as Tom Lehrer said, "Base 8 is just like base 10 really, if you're missing two fingers."

Ultimately, for humans to be able to read and understand a number from a computer, it has to be converted to*characters* and displayed on some device. As @retrolefty indicated, the Arduino Serial.print() function can take a number stored in the MCU and convert it to a *character representation* in any of several bases: binary (base 2), octal (base eight), decimal (base 10), or hexadecimal (base 16).

If the problem here is to output a number in a given base, then Serial.print() is one way. On the other hand, if the problem is for a person to*input* a number in a given base, and convert it to the proper internal representation, then that is a different algorithm.

Sorry for the long-winded reply, we need more information to help, the question as asked is too open to interpretation.

Tom Lehrer:

New Math (http://www.youtube.com/watch?v=wIWaJ0sy03g&feature=related)

So I'm not sure there is such a thing as an algebraic equation to do base conversion. But as others pointed out, there certainly are

On the other hand, the internal representation of a number in hardware is always binary. I like to say (usually when the boss is really steamed about something) "It's all just ones and zeroes." Or as Tom Lehrer said, "Base 8 is just like base 10 really, if you're missing two fingers."

Ultimately, for humans to be able to read and understand a number from a computer, it has to be converted to

If the problem here is to output a number in a given base, then Serial.print() is one way. On the other hand, if the problem is for a person to

Sorry for the long-winded reply, we need more information to help, the question as asked is too open to interpretation.

Tom Lehrer:

New Math (http://www.youtube.com/watch?v=wIWaJ0sy03g&feature=related)

Title: **Re: Binary Equation**

Post by:**borref** on **Jul 19, 2011, 07:20 pm**

Post by:

Sorry for the long-winded reply, we need more information to help, the question as asked is too open to interpretation.

You're being too nice - the question as asked makes no sense whatsoever.

Is there an algebraic equation to convert between base10 and binary?

The issue here is that "base10" and "binary" are terms related to visual representation whereas algebra involves numeric quantities. Whether the quantities are visualized as binary, octal, hex or decimal has no bearing on algebra. He may as well ask for an equation to convert between blue and red numbers or bold and normal numbers.

Title: **Re: Binary Equation**

Post by:**JChristensen** on **Jul 19, 2011, 09:15 pm**

Post by:

You're being too nice - the question as asked makes no sense whatsoever.

Could be. I may just be having one of those days XD Might have asked a question like that myself once, don't exactly remember though lol...

Quote

The issue here is that "base10" and "binary" are terms related to visual representation whereas algebra involves numeric quantities. Whether the quantities are visualized as binary, octal, hex or decimal has no bearing on algebra. He may as well ask for an equation to convert between blue and red numbers or bold and normal numbers.

Good analogy!

Title: **Re: Binary Equation**

Post by:**Utopia** on **Jul 19, 2011, 09:22 pm**

Post by:

Is there an algebraic equation that Arduino can run to convert from base 10 to binary form? (and binary to base 10;algebraic)

If you mean an algorithm (steps to follow) I mentioned one earlier, and I can provide code if you wish. If however, you really mean algebraic, then no - that is, if you're hoping for a formula (not a function) that gives you

f(15)=1111

I know of nothing. A function, on the other hand...

Title: **Re: Binary Equation**

Post by:**fuzzball27** on **Jul 19, 2011, 11:45 pm**

Post by:

haha oh how I love programming nerd conversations!

Thanks for the help.

Thanks for the help.

Title: **Re: Binary Equation**

Post by:**Grumpy_Mike** on **Jul 20, 2011, 12:05 am**

Post by:

Quote

how I love programming nerd conversations!

Well if you don't ask a sensible question all we can do is to guess what you actually mean. The answer to your original question is of course no there isn't.

But trying to be helpful we try and second guess why you would want to do this anyway, this leads on to the discussion you have seen.

Title: **Re: Binary Equation**

Post by:**robtillaart** on **Jul 20, 2011, 12:20 am**

Post by:

Quote

how I love programming nerd conversations!

I take that as a compliment, we didn't help solve your problem but still made you happy

(Or are you a textwriter looking for inspiration for some sitcom? ;)

Back to your original question

Quote

Let me rephrase: "Is there an algebraic equation to convert between base_{10}and binary?"

It is still not clear what you want, Please give an example how such an algebraic equation looks like, and where the base 10 and binary fits in....

There are 10 types of people in this world those that know binary and those that don't.

Title: **Re: Binary Equation**

Post by:**fuzzball27** on **Aug 03, 2011, 07:04 pm**

Post by:

Sorry for the delayed reply. Because of this conversation I realized the difference between value and *representation* of value. I guess the best way to answer my original question would be: a = a xD

Title: **Re: Binary Equation**

Post by:**Grumpy_Mike** on **Aug 03, 2011, 07:43 pm**

Post by:

Quote

I realized the difference between value and representation of value.

Or to put it the other way round, a computer manipulates bit patterns, it is the interpretation of those bit patterns that give them meaning.

For example a bit pattern can have a numeric value if you interpenetrate it one way and that bit number can be expressed in any number of different number basis. However the same bit pattern can be interpreted in a different way to mean a number that ranges over positive and negative values. The same bit pattern might be interpreted as a floating point numeric value or a fixed point numeric value or a BCD (binary encoded decimal) value or even an alphabetic character according to any one of a number of conventions like ASCII, Murry Code, Mores Code ... the list goes on.

Just remember it is only bit patterns not numbers that a computer manipulates.

Title: **Re: Binary Equation**

Post by:**ArduinoM** on **Sep 04, 2011, 07:44 pm**

Post by:

try this:

http://www.wikihow.com/Convert-from-Decimal-to-Binary

(this is a 10bit conversion scheme)

in an arduino sketch you would use / (division) and % (modulo) on integers in a while loop (or for, or any flavour of loop you desire)

you would not find an algebraic function that is not recursive, to do your work.

D.

http://www.wikihow.com/Convert-from-Decimal-to-Binary

(this is a 10bit conversion scheme)

in an arduino sketch you would use / (division) and % (modulo) on integers in a while loop (or for, or any flavour of loop you desire)

you would not find an algebraic function that is not recursive, to do your work.

D.