Great explanations by siOscar and Tagamanila!
For me, it helps to know the larger context of the conversation or text as well. Knowing the question being asked helps me to differentiate between using hindi or wala.
For example:
Gutom ka ba? Are you hungry?
Opo, gutom ako. Yes ma'am/sir, I'm hungry.
OR
Hindi ho, hindi ako gutom. No ma'am/sir, I'm not hungry.
It's a simple question and answer, but knowing the question helps lead me to use hindi for a negative response, in the example above, because it's a direct yes or no question.
For a wala example, if someone is asking me a "nasa" question, and "nasa" indicates location:
Nasa mesa ba ang aklat? Is the book on the table?
Oo. Nasa mesa ang aklat. Yes. The book is on the table.
OR
Wala. Wala sa mesa ang aklat. No. The book is not on the table.
In this case, I use "wala" for the negative response because the book is not on the table or absent from the location specified.
Great question @Fujishooter! I have these type of questions myself. Hope this helps a little.