Help with LCD conversion

what I have here is a code that converts binary values of 4 digits and converts it into BCD (Binary encoded in Decimal by method 8421) and shows it on the LCD.
now i want to make a make a Binary to BCH Converter, Binary encoded in hexadecimal), but I don't know how to start. Can anyone help me with it?

#include<LiquidCrystal.h>

LiquidCrystal lcd1(8,9,10,11,12,13);
int a, b, c, d, m,s1,s2,s3,s4,result;


void setup()
{
  lcd1.begin(16,2);// 16 x 2 16 characters in 2 lines
  Serial.begin(9600); //PRINT Serial
     
  pinMode(5,INPUT); // - A  (1-CH)
  pinMode(4,INPUT); // - B   (2-CH)
  pinMode(3,INPUT); // - C   (3-CH)
  pinMode(2,INPUT); // - D (4-CH)
  pinMode(A0,INPUT); // key m - 0 IFTM and 1 DECIMAL (DEC)Red

}

void loop()
{
  a = digitalRead(5);
  b = digitalRead(4);
  c = digitalRead(3);
  d = digitalRead(2);
  m = digitalRead(A0);
  
  if(a == 1){
    s1 = 8;
  }else{
    s1 = 0;
  }
  if(b == 1){
    s2 = 4;
  }else{
    s2 =0;
  }  
  if(c == 1){
    s3 = 2;
  }else{
    s3 =0;
  }
  if (d ==1){
    s4 = 1;
  }else{
    s4 = 0;
  }
  result = s1 + s2 + s3 + s4;
  Serial.print(m);
  Serial.print(' ');
  Serial.println(result);
  
  if(m == 0){
    lcd1.setCursor(0,0);
    lcd1.print("IFTM");// print IFTM
  }else if (m == 1){
    lcd1.setCursor(0,0);
    lcd1.print("DEC ");// print DEC
  }
  
  if(result < 10){
    lcd1.setCursor(0,1);
    lcd1.print("0");
    lcd1.setCursor(1,1);
    lcd1.print(result);
  }else{
    lcd1.setCursor(0,1);
    lcd1.print(result);
    }
    
    lcd1.setCursor(7,0);
    lcd1.print("a");
    lcd1.setCursor(7,1);
    lcd1.print(a);
  
    lcd1.setCursor(8,0);
    lcd1.print("b");
    lcd1.setCursor(8,1);
    lcd1.print(b);
  
    lcd1.setCursor(9,0);
    lcd1.print("c");
    lcd1.setCursor(9,1);
    lcd1.print(c);
  
    lcd1.setCursor(10,0);
    lcd1.print("d");
    lcd1.setCursor(10,1);
    lcd1.print(d);
  
  	delay(800);
  
  }

What does the code actually do? How is that different from what you want to do?

poliekos2:
what I have here is a code that converts binary values of 4 digits and converts it into BCD (Binary encoded in Decimal . . .

BCD does NOT mean Binary encoded in Decimal. The word 'in' does not belong in the definition.

If you want to include the word 'in' then I suppose you could say Decimal encoded in Binary or DCB.)

When you convert a decimal number such as 234 to binary you get 11101010 or 1110 1010.

To convert that same number to BCD you just convert each digit separately.
The '2' converts to 0010, the '3' converts to 0011, and the '4' converts to 0100.
When you run them all together you get 001000110100 or 0010 0011 0100.

There is no simple correlation between the binary and the BCD notation which is why you need a program such as the one you wrote.

On the other hand hexadecimal notation is already 'binary encoded'.
The decimal number number 234 happens to be EA when expressed in hex so I'll use that number as an example.

When you convert the hex number EA to binary you get 11101010 or 1110 1010.
When you separately convert each higit (hexadecimal digit) to binary the 'E' converts to 1110, and the 'A' converts to 1010. When you run them together you get 1110 1010.

Don

What you want to do is take advantage of this code to print the values from 0 to 15 in hexa?