Just add your return value to 65536 and you should have the correct value. ie. val(&HFFFF) returns -1 therefore 65536 + -1 =65535 val(&HFFFE) returns -2 therefore 65536 + -2 =65534