- #1

- 293

- 0

Can decoders and encoders be used?

You are using an out of date browser. It may not display this or other websites correctly.

You should upgrade or use an alternative browser.

You should upgrade or use an alternative browser.

- Thread starter Avichal
- Start date

- #1

- 293

- 0

Can decoders and encoders be used?

- #2

chiro

Science Advisor

- 4,797

- 133

The standard algorithm is known as the DIV/MOD algorithm in programming. Here is an intuitive idea of how it works:

http://www.mathsisfun.com/base-conversion-method.html

- #3

- 293

- 0

This is how we do it. Do computers do the same thing?

- #4

chiro

Science Advisor

- 4,797

- 133

This is how we do it. Do computers do the same thing?

Yep.

- #5

- 293

- 0

- #6

chiro

Science Advisor

- 4,797

- 133

You can divide a number in binary format by any other whole number (not 0 though) and get the remainder (i.e. the modulus) and the quotient (i.e. the result).

In C++ the modulus is % and integer division is just /. If you want to make sure you get the right answer just calculate the modulus, subtract that from the value and then do the division and you are guaranteed to get the right answer.

Doesn't matter if its 10358 / 2 or 10358 / 23, it's the same kind of operation.

- #7

rcgldr

Homework Helper

- 8,775

- 572

Depends on the computer and the application. In the case of mainframes and other computers used for accounting type applications, the data is kept in decimal as BCD strings and the math is performed on those BCD strings, to eliminate any rounding issues due to conversion to binary and back. COBOL is an example of a high level language that includes BCD and binary based math. The cpus on a PC include basic add and subtract operations for BCD, which can be the basis for doing BCD based math on a PC.I just studied BCD ... What is the current method to convert decimal to binary and back to decimal?

Otherwise, conversion is done by division (and using remainder) or multiply, depending if converting from another base to binary or from binary to another base, or if converting the integer or fractional (the part to the right of the decimal or binary point) portion of a number.

Last edited:

- #8

DrGreg

Science Advisor

Gold Member

- 2,360

- 1,273

One way to to this is to calculateLets say we give the number 1206 as input. But first computer needs to convert it to binary.

(((((**1** × 10) + **2**) × 10) + **0**) × 10) + **6**

The computer already knows what 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, and 10 are in binary -- they have been worked out in advance and stored in memory -- and so can perform the above calculation in binary.

- #9

- 1

- 0

How do you calculate e.g 321 decimal form to now how many bytes you can store?

- #10

- 71

- 4

It's easier to show C++ func doing this stuff:

Code:

```
template<class Num>bool ParseUnsignedBase10(const char** p, const char* end, Num* res)
{
const char* p1 = *p;
Num v = 0;
while(p1 < end){
if(*p1<'0' || *p1>'9') break;
Num v1 = v*10 + (*p1 - '0');
if(v1 < v)break;
v = v1;
};
if(p1 == *p)return false;
*p = p1;
*res = v;
return true;
}
```

Share:

- Replies
- 25

- Views
- 2K