Bitwise issue in Picture Entities card

I recently raised a topic, https://community.home-assistant.io/t/old-style-floorplan-question/362061, that asked how to combine more than one boolean sensor into a values that could be interpreted in a picture entity card to determine which of several images should be displayed. I had 3 booleans and this eventually was applied by creating a bitwise based template sensor, with values 1, 2 and 4 added together representing each on state. For 3, this was simple (ie could check the decimal value up to 7).

However, I have since come up with a much more complex set of Booleans, up to 8 in fact, that I would need to do a similar thing but actually use the bitwise 1/0 values properly and have the equivalent of if statements that combine up to 4 of these. So there can be a combination of 4 booleans that define a single image to be used. I have about 6 images to select from so there are a number of combinations I need to recognise. There are many references to bitwise in forums and help sites but they don’t really make it clear how I can use them.

I have attached my initial idea for the template sensor (please note this is a bit of pseudo code as I am yet to identify the exact states for my entities but the basic concept is they are a boolean on/off, open/closed state for each).

  - platform: template
    sensors:
      lights_curtains_doors_binary:
        friendly_name: "Lights Curtains and Doors"
        value_template: >-
          {% set bit1 = 1 if is_state('switch.kitchen_light', 'on') else 0 %}
          {% set bit2 = 2 if is_state('light.conservatory_lights', 'on') else 0 %}
          {% set bit3 = 4 if is_state('light.doorway_light', 'on') else 0 %}
          {% set bit4 = 8 if is_state('light.living_room_light', 'on') else 0 %}
          {% set bit5 = 16 if is_state('binary_sensor.conservatory_door_contact_sensor', 'on') else 0 %}
          {% set bit6 = 32 if is_state('binary_sensor.kitchen_door_contact_sensor', 'on') else 0 %}
          {% set bit7 = 64 if is_state('binary_sensor.front_door_contact_sensor', 'on') else 0 %}
          {% set bit8 = 128 if is_state('cover.Living_room_curtains', 'on') else 0 %}
          {{ bit1 + bit2 + bit3 + bit3 + bit4 + bit5 + bit6 + bit7 + bit8}}

A typical example of the pseudo if statement I need is:

if doorway_light on (bit 3 value 4) and living_room_light on (bit 4 value 8) and front_door open (bit 7 value 64) and curtains closed (bit 8 value 0??? I think…), state-image is image xxxx.png (where all these are represented in the image)

If these were added together correctly for each sensor, what code would I have in my Entity statement in the picture card to get the bits set to 1 and use these as “if” statements for the state-image selections?

I simplified the booleans so it now works.