Pages: [1]   Go Down
Author Topic: Binary Equation  (Read 5052 times)
0 Members and 1 Guest are viewing this topic.
United States
Offline Offline
Full Member
***
Karma: 0
Posts: 104
Indubitably
View Profile
 Bigger Bigger  Smaller Smaller  Reset 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 Offline
Brattain Member
*****
Karma: 331
Posts: 16523
Measurement changes behavior
View Profile
 Bigger Bigger  Smaller Smaller  Reset 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.  smiley-wink

Logged

Victoria, BC, Canada
Offline Offline
Full Member
***
Karma: 0
Posts: 222
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset 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
Offline Offline
Shannon Member
*****
Karma: 170
Posts: 12465
In theory there is no difference between theory and practice, however in practice there are many...
View Profile
 Bigger Bigger  Smaller Smaller  Reset 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 Offline
Full Member
***
Karma: 0
Posts: 104
Indubitably
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

fuzzball27 >>-->

Grand Blanc, MI, USA
Offline Offline
Faraday Member
**
Karma: 71
Posts: 3515
CODE is a mass noun and should not be used in the plural or with an indefinite article.
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset 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.

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

Tom Lehrer:


Logged

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

Offline Offline
Edison Member
*
Karma: 3
Posts: 1001
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Grand Blanc, MI, USA
Offline Offline
Faraday Member
**
Karma: 71
Posts: 3515
CODE is a mass noun and should not be used in the plural or with an indefinite article.
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset 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 smiley-lol  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/

Victoria, BC, Canada
Offline Offline
Full Member
***
Karma: 0
Posts: 222
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset 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 Offline
Full Member
***
Karma: 0
Posts: 104
Indubitably
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

fuzzball27 >>-->

Manchester (England England)
Offline Offline
Brattain Member
*****
Karma: 509
Posts: 31483
Solder is electric glue
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset 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
Offline Offline
Shannon Member
*****
Karma: 170
Posts: 12465
In theory there is no difference between theory and practice, however in practice there are many...
View Profile
 Bigger Bigger  Smaller Smaller  Reset 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? smiley-wink


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.
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 Offline
Full Member
***
Karma: 0
Posts: 104
Indubitably
View Profile
 Bigger Bigger  Smaller Smaller  Reset 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)
Offline Offline
Brattain Member
*****
Karma: 509
Posts: 31483
Solder is electric glue
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset 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 Offline
Sr. Member
****
Karma: 0
Posts: 344
Just dip it in mercury and power it up
View Profile
 Bigger Bigger  Smaller Smaller  Reset 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
Jump to: