Stuart Bingham edged out Ding Junhui 10-9 in a thriller to secure his place in the World Championship last 16.