Культурный офтопик
 help / color / mirror / Atom feed
From: "Damir Shayhutdinov" <lost404@gmail.com>
To: "культурный офтопик" <smoke-room@lists.altlinux.org>
Subject: Re: [room] Щодо: Двоичные числа
Date: Thu, 8 Feb 2007 20:01:10 +0300
Message-ID: <679044850702080901w1aee46cbsc95dd7e2cf0e484b@mail.gmail.com> (raw)
In-Reply-To: <e12fd2db0702080831p48d918fbofaec2e701032e242@mail.gmail.com>

> так знает кто-то правило? Ибо пользоваться qalculator я тоже умею, но
> беглый взгляд в его исходники убедил меня что алгоритм преобразования
> я из него не вытащу... :)
Вот например:

надо перевести число 0.625 в двоичное.

0. Остаток = дробной части
1. Если остаток равен 0, прекратить алгоритм
2. Остаток < 0.5 ?
3. Если да, то записать 0, и умножить остаток на  2.
4. Если больше или равен 0.5 - то записать 1, отнять 0.5 и умножить на 2.
5. Перейти к пункту 1.

Например:
0.625 (0, <тут будут цифры дроби>)
0.625 != 0
Оно больше чем 0.5 - по этому надо записать после запятой 1, отнять
0.5 и умножить на 2.
0.625 - 0.5 = 0.125 (0,1<>)
0.125 * 2 = 0.25 (0,1<>)
Теперь опять на пункт 1.
0.25 != 0
0.25 < 0.5 ? да. Поэтому записываем 0, умножаем на 2.
0.25 * 2 = 0.5 (0,10<>)
Переходим опять к пункту 1.
0.5 < 0.5 ? нет. Записываем 1, отнимаем 0.5, умножаем на 2
0.5 - 0.5 = 0 (0,101<>)
0 * 2 = 0 (0,101<>)
Переходим к пункту 1. В остатке получили 0. Алгоритм закончен.
Итого: 0.625 = 0.101

В принципе, для всех дробей, делитель которых не является степенью 2 -
результатом будет  периодическая дробь
.
Чтобы определить период, надо продолжать алгоритм до тех пор, пока
остаток не начнет повторяться. Тогда та часть, которая была получена
между двумя одинаковыми остатками, будет периодом.

  reply	other threads:[~2007-02-08 17:01 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-02-08 15:52 gns
2007-02-08 15:57 ` Damir Shayhutdinov
2007-02-08 16:00   ` gns
2007-02-08 16:31     ` Eugene Ostapets
2007-02-08 17:01       ` Damir Shayhutdinov [this message]
2007-02-08 17:05         ` Damir Shayhutdinov
2007-02-09  6:47           ` Andrew Borodin
2007-02-08 21:19         ` Aleksey Korotkov
2007-02-08 21:37           ` Damir Shayhutdinov
2007-02-09  4:12             ` Aleksey Korotkov
2007-02-09  6:45             ` Nick S. Grechukh

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=679044850702080901w1aee46cbsc95dd7e2cf0e484b@mail.gmail.com \
    --to=lost404@gmail.com \
    --cc=smoke-room@lists.altlinux.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

Культурный офтопик

This inbox may be cloned and mirrored by anyone:

	git clone --mirror http://lore.altlinux.org/smoke-room/0 smoke-room/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 smoke-room smoke-room/ http://lore.altlinux.org/smoke-room \
		smoke-room@lists.altlinux.org smoke-room@lists.altlinux.ru smoke-room@lists.altlinux.com smoke-room@altlinux.ru smoke-room@altlinux.org smoke-room@altlinux.com
	public-inbox-index smoke-room

Example config snippet for mirrors.
Newsgroup available over NNTP:
	nntp://lore.altlinux.org/org.altlinux.lists.smoke-room


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git