Hello,
We are working on a project which involves comparing of two sinewaves.
These waves are generated externally through hardware which we are giving to the arduino ADC pins and the difference i.e the error between them is to be generated.
Here we have a doubt as to whether the error would be binary or hexadecimal.. and also we need to convert it into decimal...
so we require the code for binary to decimal or hexadecimal to decimal conversion..
Please help..
Here we have a doubt as to whether the error would be binary or hexadecimal.. and also we need to convert it into decimal...
Internally, everything is binary.
Will show you how to use the analog read command guess what the variable is an integer which is decimal.
Tom......
project12345:
Here we have a doubt as to whether the error would be binary or hexadecimal.. and also we need to convert it into decimal...
What @Awol says is quite correct.
However I find it hard to understand the thought process behind your question. Whether a number is in binary or hex or decimal it is still the same number.
Suppose you have a short piece of code like this
diff = highValue - lowValue;
There is no need to be concerned about how the Arduino represents the values - that is a job for the compiler to do behind the scenes. (I am assuming the variables have already been declared elsewhere in the program)
If you want to view the value of diff you can do so with
Serial.printlin(diff);
which, by default, shows you the decimal representation of the value.
...R
project12345:
Here we have a doubt as to whether the error would be binary or hexadecimal
It's neither - it's just a number. Decimal and hexadecimal are ways to represent a number textually and unless/until you convert the number to text it is neither decimal, hexadecimal, octal or anything else - it is just a number.
There are lots of ways to convert a number to text in decimal format and the 'best' way for a given situation will depend what you want to do with the string afterwards. Various interfaces that output strings let you provide a number to a print method that will format it for you. For example Serial.print() will print a number in decimal format by default. If you want to convert the number to a string within your own code, you can use snprintf() to do that.
Decimal and hexadecimal are ways to represent a number textually and unless/until you convert the number to text it is neither decimal, hexadecimal, octal or anything else - it is just a number.
Well I would go further and say until you give it context it is just a bit pattern. That bit pattern can be interpreted as a number in several different ways. Notice I say interpreted and not converted to because no conversion takes place.
Ways a bit pattern can be interpreted as a number:-
- Unsigned binary value
- Signed binary value ( two's complement form )
- Signed binary value ( one's complement form )
- Signed binary value ( sign and magnitude form )
- BCD number
- Fixed point binary fraction
- Floating point binary fraction with exponent
I am sure I have missed some. The point is they can all be the same bit pattern and be interpreted as different numbers.
Then once you have the number there is all the text interpretation of that number as mentioned above.