Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 4 years ago.
Improve this question
I have a problem in C, I am not allowed to use floats as the microcontroller it will be flashed does not support that data type. Now all my integers are being rounded off as it should. How do I handle this case?
A short research indicates using bit wise operation such as left shift and right shift. I know what are these operations. But I do not know how to use these operations to achieve what I want.
Another possibility is the Q number format.
You will get some results if you google "Q number format" or some variations.
It is often used for some DSP related topics in C. Here another blog post that explains that number format and here is an example code implementation for q-numbers in C.
In general you can say that q-numbers represent a number between -1 and 1 without using floating point arithmetic.
Normally a microcontroller don't have a floating point unit, everything works with integers. But its up to you which unit you like for your integers.
For example:
100 could be 100 cm or 1,00 m
1000 could be 100,0 cm or 1,000 m and so on..
Please have a look at the description:
electronic.stackexchange
Related
Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 5 years ago.
Improve this question
My question is pretty simple. I am newbie in microcontrollers world and trying to understand usage of haxadecimal or decimal naming conventions. I saw much C code and first part of programmers uses decimal naming convention:
#define TEST_BUTTON_PORT 1
#define TEST_BUTTON_BIT 19
the second part uses hexadecimal way:
#define IOCON_FUNC0 0x0
#define IOCON_FUNC1 0x1
Is any important reason for different conventions? Is just a programmer choice?
The purpose of hex is to ease the use of binary numbers, since binary is very hard for humans to read. Some examples when hexadecimal is used:
Describing binary numbers and binary representations.
Dealing with hardware addresses.
Doing bit-wise arithmetic.
Declaring bit masks/bit fields.
Dealing with any form of raw data, such as memory dumps, machine code or data protocols.
An exception to this is, oddly, when specifying the number of bits to shift. This is almost always done in decimal notation. If you wish to set bit 19 you would usually do it by writing:
PORT |= 1 << 19;
This assuming bits are enumerated from 0 to n.
I suppose this is because decimal format is more convenient when enumerating things, such as bit/pin numbers. (And manufacturers of MCUs etc usually enumerate pins with decimal notation.)
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 7 years ago.
Improve this question
Problem Statement
Addition is a very basic operation in mathematics. Jimmy was very weak in addition, so his father decided to teach him. Jimmy is given a number and has to perform addition on all the digits of that number till that the large number gets converted into a single digit. Your task is to prepare a program for him so that he can easily find out the final number.
Input Format
First line contains T (1<=T<=100) the number of test cases.
Each test case contains integer N (1<=N<=10^100).
Output Format
For each test case, output the one digit number by repeatedly adding the digits.
Constraints
1<=T<=100
1<=N<=10^500
I'd represent the very large input number as char, and the total of the digits (first pass) will easily fit in an int. You'll need a little more than simple arithmetic, but it shouldn't be difficult (case seems a likely way to manage the job).
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 7 years ago.
Improve this question
I'am trying to write a C code to add, subtract, multiply and divide 2 numbers each containing 100 digits. This should include the use of arrays.
Can anyone please give me any suggestions, a pseudo code or a sample code?
To be more clear
The user will enter 2 numbers(Integers)
Each number can comprise of 100 or less digits i.e integer a can be 10 or 234 or 43582 or 23456788 or 23445667788...... etc. Same for integer b.
Now taking these two integers I have to perform the arithmetic operations of Addition,Subtraction,Division,Multiplication,Modulas(%)
You could try using the GMP Library as answered in this question. It can perform Bigint operations in both C and C++. Also if you are fine with C++ code for Bigint you could check out this blogpost.
You are looking for hints on implementing arbitrary precision arithmetic. Start be reading this article: https://en.wikipedia.org/wiki/Arbitrary-precision_arithmetic , then search for bignum c code with a search engine, sample implementations are easy to find. Avoid full blown packages such as gnu MP because they are too advanced and not the right starting point.
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 7 years ago.
Improve this question
Hello everyone I was going through a few programming questions and encounter one strange thing, The problem asked me to do some logic which is not relevant or nor I am asking the logic here, But the question involved the integers and said that I should keep in consideration that integer value be less than 10000000000
My doubt what data type to be used to store such ranges or, Lets just assume that some C program is used in some banking application which involves huge no of these magnitude, How do we store such huge no, Note: Even type 'long long' wont be able to store such huge no , Then how do we store such no ?
if possible use int64_t instead of long long that is defined in standard library header stdint.h. That holds 64 bit integers for sure. Larges number that can be represented is 2**63-1 and that is 9223372036854775807 (9e18). So it can hold 10000000000.
You could imagine the value stored in a database where numeric precision can be specified for data columns. But it's more likely that the particular value is specified to force you to think about how the algorithm or code would handle numeric overflow.
BTW, many systems use a 64 bit long long, which could hold the value you mention. Here's a great site to experiment with numbers and gain an intuitive feel for this:
http://www.wolframalpha.com/input/?i=2%5E64
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
I'm using long double in a C program to compute 2D images of the Mandelbrot Set but wish to have further precision to zoom deeper.
Are there any performance gains to be had from an arbitrary precision maths library that can restrict the amount of precision as required, rather than leaping from long double precision straight into arbitrary precision?
Which is the fastest of the arbitrary precision maths libraries?
'fastest' is going to be somewhat dependent on your platform and intended use.
The MPFR Library
GMP
This wiki article contains links to several libraries.
If you need more precision, see qd at http://crd.lbl.gov/~dhbailey/mpdist/.