Branch: Tag:

2004-03-15

2004-03-15 21:51:25 by Martin Nilsson <mani@lysator.liu.se>

Hopefully I never have to write this code again.... (swap_word, swap_long)

Rev: lib/modules/Int.pmod:1.7

41:   //! @expr{--without-bignum@} (which is discouraged), then all   //! arithmetic operations will instead silently wrap around at these   //! limits. +  + //! Swaps the upper and lower byte in a word. + int(0..65535) swap_word(int(0..65535) i) { +  return ((i&255)<<8) | ((i&(255<<8))>>8); + } +  + //! Swaps the upper and lower word in a longword, and the upper and + //! lower bytes in the words. Simply put, the bytes are reversed. + int(0..4294967295) swap_long(int(0..4294967295) i) { +  return ((i&255)<<24) | ((i&(255<<8))<<8) | +  ((i&(255<<16))>>8) | ((i&(255<<24))>>24); + }