Shop OBEX P1 Docs P2 Docs Learn Events
integers hi bytes & lo bytes — Parallax Forums

integers hi bytes & lo bytes

darnitdarnit Posts: 25
edited 2006-04-24 14:29 in General Discussion
How do I set the values of the hi-bytes and lo-bytes for intgers?· In pbasic it is easy....

Holder.LOWBYTE = D1
Holder.HIGHBYTE = D2

the only reference to this i can find in the manual is on page 121. and im not sure what the shift laft is doing.

Comments

  • Peter VerkaikPeter Verkaik Posts: 3,956
    edited 2006-04-24 14:29
    To set an int two 2 bytes low and high use

    int value = (high<<8)|(low&0xFF);

    To extract high and low bytes from an int use

    int low = value&0xFF;
    int high = value>>>8;

    or define a method to make a word from bytes

    int word(int low, int high) {
    · return (low&0xFF)|(high<<8);
    }

    regards peter
Sign In or Register to comment.