I l@ve RuBoard Previous Section Next Section

17.13 Answers to Chapter Questions

Answer 17-1: The problem is that memset is a character-fill routine. An integer consists of 2 or 4 bytes (characters). Each byte is assigned the value 1. So a 2-byte integer will receive the value:

    integer = 0x0101; 

The 1-byte hex value for -1 is 0xFF. The 2-byte hex value of -1 is 0xFFFF. So we can take two single-byte -1 values, put them together, and come out with -1. This works for zero also. Any other number will produce the wrong answer. For example, 1 is 0x01. Two bytes of this is 0x0101, or 257.

    I l@ve RuBoard Previous Section Next Section