Go Down

Topic: Binary Equation (Read 6556 times) previous topic - next topic

fuzzball27

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

retrolefty

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.  ;)


David Pankhurst

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'





robtillaart

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); ...
Rob Tillaart

Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -
(Please do not PM for private consultancy)

fuzzball27

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

Jack Christensen

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

MCP79411/12 RTC ... "One Million Ohms" ATtiny kit ... available at http://www.tindie.com/stores/JChristensen/

BenF


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.

Jack Christensen

#7
Jul 19, 2011, 09:15 pm Last Edit: Jul 19, 2011, 09:17 pm by Jack Christensen Reason: 1

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!

MCP79411/12 RTC ... "One Million Ohms" ATtiny kit ... available at http://www.tindie.com/stores/JChristensen/

David Pankhurst


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...

fuzzball27

haha oh how I love programming nerd conversations!
Thanks for the help.
fuzzball27 >>-->

Grumpy_Mike

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.

robtillaart


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 base10 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.
Rob Tillaart

Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -
(Please do not PM for private consultancy)

fuzzball27

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
fuzzball27 >>-->

Grumpy_Mike

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.

ArduinoM

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.

Go Up