[an error occurred while processing this directive] [an error occurred while processing this directive]
когда-то пробегало здесь такое -- (+)
(«Телесистемы»: Конференция «Микроконтроллеры и их применение»)
[an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive]

Отправлено kV 18 января 2002 г. 21:55
В ответ на: Ну, а все же как поделить unsigned на 10, с помощью сдвигов сложения и вычитания(+) отправлено abivan 18 января 2002 г. 19:12

A simple algorithm to convert binary to BCD is:

;1. Add 3 to every BCD nibble that's >=5
;2. Shift left
;Repeat until binary portion is all 0000

;Example: Convert $F9 to BCD


;0000 0000 0000 : 1111 1001
;0000 0000 0001 : 1111 0010 (shift left)
;0000 0000 0011 : 1110 0100 (shift left)
;0000 0000 0111 : 1100 1000 (shift left)
;0000 0000 1010 : 1100 1000 (add 3)
;0000 0001 0101 : 1001 0000 (shift left)
;0000 0001 1000 : 1001 0000 (add 3)
;0000 0011 0001 : 0010 0000 (shift left)
;0000 0110 0010 : 0100 0000 (shift left)
;0000 1001 0010 : 0100 0000 (add 3)
;0001 0010 0100 : 1000 0000 (shift left)
;0010 0100 1001 : 0000 0000 (shift left)

;And the left now holds BCD 249.
;MUCH easier than messing with IDIV and FDIV!!!

Алгоритм, кстати обратимый.


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

Ответы



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

E-mail: info@telesys.ru