Das Open-Control-Projekt - Die Alternative zur C-Control-I


Das Forum zur C-Control-1
Welche C-Control-Varianten existieren?
Übersicht - Suchen - Neueste 50 Beiträge - Neuer Beitrag - Login - Registrieren
INFO - FAQ - CC2-Forum - CCPro-Forum 

 Re: Word into Bytes.. why does this not work?? Kategorie: C-Control I V1.2/2.0 (von Windt H.J. - 17.05.2008 19:31)
 Als Antwort auf Re: Word into Bytes.. why does this not work?? von Achim - 17.05.2008 18:51
Hello,
ItÂ’s a thinking error of my own.
I read a long time ago that to break up a word into its 2 bytes you could do the following:

Hibyte = word / 256
Lobyte = word mod 256

-1 is nothing but decimal 65535 so I would expect to get 255 for the hibyte and 255 for the lobyte.

Greetings,
H.J. Windt

> > Why does the following program not work??
>
> It "works" for me. Why do you ask? Do you not get what you expected? Well, then your expectations weren't correct ... ;-)
> >
> > define x word[1]
> > put 0
> > #start
> > x = -1
> > print x
> > print x / 256
>
> What do you get here? Without testing I'd expect the output 0. Because -1 divided by 256 is the same as 1 divided by 256 just with a minus sign in front. (Division does take the sign into account)
> 1/256 is 0 since we have an integer division and not float. -0 prints as 0.
>
> > print x mod 255
>
> What do you get here? Without testing I'd expect the output -1.
>
> > print (x and &hff00) shr 8
>
> Totally different operation unless x is positive.
>
> HTH
>
> Bye
>  Achim

 Antwort schreiben

Bisherige Antworten:

Re: Word into Bytes.. why does this not work?? (von Achim - 17.05.2008 21:23)