From: Andrew Borodin <borodin@zarya-k.ru> To: "культурный офтопик" <smoke-room@lists.altlinux.org> Subject: Re: [room] Щодо: Двоичные числа Date: Fri, 9 Feb 2007 09:47:13 +0300 Message-ID: <20070209064713.GB3781@borodin.zarya> (raw) In-Reply-To: <679044850702080905p1940c957n5110897229c0ae77@mail.gmail.com> On Thu, Feb 08, 2007 at 08:05:20PM +0300, Damir Shayhutdinov wrote: > Уточненный алгоритм выглядит так: > > 0. Остаток = дробной части исходного числа > > 1. Если остаток равен 0, прекратить алгоритм > > 2. Остаток < 0.5 ? > > 3. Если да, то записать 0, и умножить остаток на 2. > > 4. Иначе записать 1, отнять 0.5 и умножить на 2. > > 5. Перейти к пункту 1. > Заменил "Если больше или равно 0.5" на "Иначе". Если точность задана, то все гораздо проще. Надо дробную часть умножить на число "2 в степени точность" (т. е. перенести в двоичном числе запятую на "точность" знаков вправо), отбросить у получившегося числа дробную часть (или правильно округлить до целого), и перевести получившееся целое число в двоичную форму. Затем перенести запятую назад, на "точность" знаков влево. Это и будет дробная часть. Пример: перевести число 3.625 в двоичную форму с точностью 8 знаков после запятой. С целой частью как обычно: 3d == 11b. Дробна часть: - умножаем 0.626 на 256 (256 == pow(2, 8)): 0.625 * 256 = 160.0 - отбрасываем дробную часть и преводим в двоичную форму: 160d == 10100000b. - состыковываем: 3.625d == 11.101b. -- С уважением, А. Бородин.
next prev parent reply other threads:[~2007-02-09 6:47 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 2007-02-08 17:05 ` Damir Shayhutdinov 2007-02-09 6:47 ` Andrew Borodin [this message] 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=20070209064713.GB3781@borodin.zarya \ --to=borodin@zarya-k.ru \ --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