casez treats bits that have the value z as don't care in the comparison.
module top_module (
input [7:0] in,
output reg [2:0] pos );
always @ (*) begin
casez(in)
8'bzzzzzzz1:pos = 3'd0;
8'bzzzzzz1z:pos = 3'd1;
8'bzzzzz1zz:pos = 3'd2;
8'bzzzz1zzz:pos = 3'd3;
8'bzzz1zzzz:pos = 3'd4;
8'bzz1zzzzz:pos = 3'd5;
8'bz1zzzzzz:pos = 3'd6;
8'b1zzzzzzz:pos = 3'd7;
default:pos = 3'd0;
endcase
end
endmodule
A case statement behaves as though each item is checked sequentially. Notice how there are certain inputs (e.g., 4'b1111) that will match more than one case item. The first match is chosen (so 4'b1111 matches the first item, out = 0, but not any of the later ones).