[an error occurred while processing this directive]
чтоже касается плавающей точки
(«Телесистемы»: Конференция «Микроконтроллеры и их применение»)

миниатюрный аудио-видеорекордер mAVR

Отправлено колян безпарольныи 24 февраля 2005 г. 09:45
В ответ на: на С и для кейла, забыл дописать отправлено bookreader7 24 февраля 2005 г. 08:13

то это стандартный модуль math.h
И насколько я понял свой хитрый формат float который несовместим с писишным посему пришлось писать декодер на паскале, опятьже это оказалось быстрее чем разбиаться с самим форматом и искать его привязку к стандарту. Просто взял апликуху непомню откуда и написал. Вот еше дал пацану который писал на фоксе базу, он тоже писал декодер вот по ентой пояснительной записке, привожу полный текст.


получаеш 4 байта в формате float.
Это число и есть проводимость, с ней ничего ненадо делать, просто переводиш его в нужный формат и пишеш в базу.


а вот саму расшифровку формата переводи сам)))))))))))

1110 0000 1100 1010 0000 1010 0011 0011

Принятый байт из 4: 0 1 2 3
Значение SEEE EEEE EMMM MMMM MMMM MMMM MMMM MMMM

где:
'S' represents the sign bit where 1 is negative and 0 is positive.
'E' is the two’s complement exponent with an offset of 127.
'M' is the 23-bit normal mantissa. The highest bit is always 1
and, therefore, is not stored




There are two components of a floating-point number: the mantissa and the
exponent. The mantissa stores the actual digits of the number. The exponent
stores the power to which the mantissa must be raised. The exponent is an 8-bit
value in the 0 to 255 range and is stored relative to 127. The actual value of the
exponent is calculated by subtracting 127 from the stored value (0 to 255). The
value of the exponent can be anywhere from +128 to -127. The mantissa is a
24-bit value whose most significant bit (MSB) is always 1 and is, therefore, not
stored. There is also a sign bit which indicates if the floating-point number is
positive or negative.

Using the above format, the floating-point number -12.5 would be stored as a
hexadecimal value of 0xC1480000. In memory, this appears as follows:

Address +0 +1 +2 +3
Contents 0xC1 0x48 0x00 0x00


It is fairly simple to convert floating-point numbers to and from their
hexadecimal storage equivalents. The following example demonstrates how this
is done for the value -12.5 shown above.

The floating-point storage representation is not an intuitive format. To convert
this to a floating-point number, the bits must be separated as specified in the
storage format table above. For example:
Address +0 +1 +2 +3
Format SEEEEEEE EMMMMMMM MMMMMMMM MMMMMMMM
Binary 11000001 01001000 00000000 00000000
Hex C1 48 00 00

11100000 11001010 00001010 00110011
10011100 11100100 10100110 01001100
00100000 10111100 10111110 01001100
01001100 10111110 10111100 00100000
From this illustration, you can determine the following information:
The sign bit is 1, indicating a negative number.
The exponent value is 10000010 binary or 130 decimal. Subtracting 127
from 130 leaves 3 which is the actual exponent.
The mantissa appears as the following binary number:
10010000000000000000000
There is an understood decimal point at the left of the mantissa that is always
preceded by a 1. This digit is not stored in the hexadecimal representation of
the floating-point number. Adding 1 and the decimal point to the beginning of
the mantissa gives the following:
1.10010000000000000000000
Now, adjust the mantissa for the exponent. A negative exponent moves the
decimal point to the left. A positive exponent moves the decimal point to the
right. Because the exponent is 3, the mantissa is adjusted as follows:
1100.10000000000000000000
The result is now a binary floating-point number. Binary digits left of the
decimal point represent the power of two corresponding to the position: 1100
represents (1 x8 ) + (1 x4 ) + (0 x2 ) + (0 x1 ) which equals 12.
Binary digits that are right of the decimal point also represent the power of two
corresponding to their position. However, the powers are negative: .100…
represents (1 x1/2) + (0 x1/4 ) + (0 x1/8) + … which equals .5.
Adding these values together gives 12.5 which must be negated since the sign
bit is set. So, the floating-point hexadecimal value 0xC1480000 is -12.5.


Составить ответ  |||  Конференция  |||  Архив

Ответы


Отправка ответа

Имя (обязательно): 
Пароль: 
E-mail: 

Тема (обязательно):
Сообщение:

Ссылка на URL: 
Название ссылки: 

URL изображения: 


Перейти к списку ответов  |||  Конференция  |||  Архив  |||  Главная страница  |||  Содержание  |||  Без кадра

E-mail: info@telesys.ru