SQL Server internals by Paul White
This article describes the structure of a sql_handle and shows how the batch text hash component is calculated.
sql_handle