comp.lang.ada
 help / color / mirror / Atom feed
From: "Smark" <nobody@home.com>
Subject: Re: Binary value
Date: Fri, 30 Mar 2001 14:45:45 -0600
Date: 2001-03-30T14:45:45-06:00	[thread overview]
Message-ID: <9a2r9o$kf42@cui1.lmms.lmco.com> (raw)
In-Reply-To: 9a2qhh$jee4@cui1.lmms.lmco.com


"Smark" <nobody@home.com> wrote in message
news:9a2qhh$jee4@cui1.lmms.lmco.com...
>
> "chris.danx" <chris.danx@ntlworld.com> wrote in message
> news:K84x6.4066$MZ2.743519@news2-win.server.ntlworld.com...
> > > I see... that answers half of my question. This presumes I wanna convert
> > > from binary to Integer. But is it possible to "convert" a Integer value to
> > > binary.
> >
> > Suppose you have the value 123 in binary.  To convert to binary you need to
> > follow this algorithm.
> >
> > while num /= 0 loop
> >     rem := num mod 2;    -- get remainder
> >     num := num - rem;
> >     add rem'image to front* of string;
> > end loop;
> >
> > {I think this is the correct algorithm!}
>
> Well, Chris, you would probably change your mind if you tried it!
> As in your example, say you start with 123.
>
> First pass through loop:
> rem := 123 mod 2 ( = 1)
> num := 123 - 1 ( = 122)
> add "1" to front of string   -- so the string now looks like "1"
>
> Second pass:
> rem := 122 mod 2 ( = 0)
> num := 122 - 0 ( = 122)
> add "0" to front of string   -- so the string now looks like "01"
>
> Third pass:
> rem := 122 mod 2 ( = 0)
> num := 122 - 0 ( = 122)
> add "0" to front of string   -- so the string now looks like "001"
>
> Beginning to see a problem here?
>
> I think the algorithm you were trying to think of goes something like:
>
Okay, I take it back.  The algorithm I provided does work, but it is
not the one you were thinking of.  That would be more like:

while num /= 0 loop
    rem := num mod 2;    -- get remainder
    num := Floor(num/2);
    add rem'image to front* of string;
end loop;

Mark
Arlington, Texas





  reply	other threads:[~2001-03-30 20:45 UTC|newest]

Thread overview: 23+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2001-03-30 16:10 Binary value Bob Gratton
2001-03-30 16:54 ` Marin David Condic
2001-03-30 17:16   ` Bob Gratton
2001-03-30 17:41     ` Marin David Condic
2001-03-30 18:20       ` Bob Gratton
2001-03-30 19:58         ` Marin David Condic
2001-03-30 18:21     ` chris.danx
2001-03-30 20:03       ` Marin David Condic
2001-03-30 20:32       ` Smark
2001-03-30 20:45         ` Smark [this message]
2001-03-30 21:19           ` chris.danx
2001-03-31  5:23       ` Phaedrus
     [not found]         ` <3AC5C72F.8108A613@earthlink.net>
2001-04-01 19:52           ` Phaedrus
2001-04-01 22:04             ` Robert A Duff
2001-04-01 22:35               ` David C. Hoos, Sr.
2001-04-02 12:49               ` Marc A. Criley
2001-04-02 13:33             ` chris.danx
2001-04-02 14:33             ` Marin David Condic
2001-04-02 16:43       ` Jeffrey Carter
2001-04-02 17:36         ` chris.danx
2001-04-02 18:03           ` Robert A Duff
2001-04-02 17:54         ` Robert A Duff
2001-03-30 17:03 ` Larry Hazel
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox