INFO - FAQ - CC2-Forum - CCPro-Forum |
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 |