Pages: [1]   Go Down
 Author Topic: Binary Equation  (Read 6095 times) 0 Members and 1 Guest are viewing this topic.
United States
Offline
Full Member
Karma: 0
Posts: 104
Indubitably
 « on: July 18, 2011, 07:34:31 pm » Bigger Smaller Reset

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

fuzzball27 >>-->

Left Coast, CA (USA)
Offline
Brattain Member
Karma: 361
Posts: 17294
Measurement changes behavior
 « Reply #1 on: July 18, 2011, 08:00:01 pm » Bigger Smaller Reset

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.

 Logged

Offline
Full Member
Karma: 0
Posts: 222
 « Reply #2 on: July 19, 2011, 12:41:46 am » Bigger Smaller Reset

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'

 Logged

Global Moderator
Netherlands
Online
Shannon Member
Karma: 217
Posts: 13717
In theory there is no difference between theory and practice, however in practice there are many...
 « Reply #3 on: July 19, 2011, 04:08:12 am » Bigger Smaller Reset

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

Rob Tillaart

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

United States
Offline
Full Member
Karma: 0
Posts: 104
Indubitably
 « Reply #4 on: July 19, 2011, 07:00:18 am » Bigger Smaller Reset

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

fuzzball27 >>-->

Grand Blanc, MI, USA
Online
Karma: 95
Posts: 4084
CODE is a mass noun and should not be used in the plural or with an indefinite article.
 « Reply #5 on: July 19, 2011, 10:46:02 am » Bigger Smaller Reset

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.

Tom Lehrer:

 Logged

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

Offline
Edison Member
Karma: 3
Posts: 1001
Arduino rocks
 « Reply #6 on: July 19, 2011, 12:20:07 pm » Bigger Smaller Reset

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

Grand Blanc, MI, USA
Online
Karma: 95
Posts: 4084
CODE is a mass noun and should not be used in the plural or with an indefinite article.
 « Reply #7 on: July 19, 2011, 02:15:31 pm » Bigger Smaller Reset

You’re being too nice – the question as asked makes no sense whatsoever.

Could be.  I may just be having one of those days  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!

 « Last Edit: July 19, 2011, 02:17:38 pm by Jack Christensen » Logged

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

Offline
Full Member
Karma: 0
Posts: 222
 « Reply #8 on: July 19, 2011, 02:22:43 pm » Bigger Smaller Reset

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

United States
Offline
Full Member
Karma: 0
Posts: 104
Indubitably
 « Reply #9 on: July 19, 2011, 04:45:00 pm » Bigger Smaller Reset

haha oh how I love programming nerd conversations!
Thanks for the help.
 Logged

fuzzball27 >>-->

Manchester (England England)
Online
Brattain Member
Karma: 626
Posts: 34170
Solder is electric glue
 « Reply #10 on: July 19, 2011, 05:05:51 pm » Bigger Smaller Reset

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

Global Moderator
Netherlands
Online
Shannon Member
Karma: 217
Posts: 13717
In theory there is no difference between theory and practice, however in practice there are many...
 « Reply #11 on: July 19, 2011, 05:20:01 pm » Bigger Smaller Reset

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?

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

Rob Tillaart

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

United States
Offline
Full Member
Karma: 0
Posts: 104
Indubitably
 « Reply #12 on: August 03, 2011, 12:04:59 pm » Bigger Smaller Reset

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
 Logged

fuzzball27 >>-->

Manchester (England England)
Online
Brattain Member
Karma: 626
Posts: 34170
Solder is electric glue
 « Reply #13 on: August 03, 2011, 12:43:24 pm » Bigger Smaller Reset

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

Norway
Offline
Sr. Member
Karma: 0
Posts: 344
Just dip it in mercury and power it up
 « Reply #14 on: September 04, 2011, 12:44:17 pm » Bigger Smaller Reset

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

 Pages: [1]   Go Up