Pergunta

I am trying to perform arithmetic using only 16-bit signed words. I need to be able to perform addition, multiplication, etc.

As an example I need to subtract two data values, below is an example: 7269.554688-46.8 or 4385.6616210938 + 32.2

However, these values need to be converted into 16-bit words and then the subtraction, multiplication, or addition can be performed.

I could also use multiple 16-bit words to store one value.

How would I go about performing operations like addition, subtraction and multiplication and how would I convert all of my input values appropriately so that the decimal points always line up properly?

Foi útil?

Solução

What platform are you coding for? To perform the operations you've given as an example, you would need a floating point unit. Floating point numbers are usually represented through 32 bits or 64 bits, rarely 16 bit.

If you don't have one and all you have are simple operations on 16 bit integers, you could emulate a floating point unit, but that is not a trivial task.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top