2020-01-26

BCD decryption

BCD number is expressed by one byte, the number of decimal two, each represented by a four bit. So if a hexadecimal BCD number is 0x12, it is the expression of decimal 12. But Xiao Ming never learned BCD, BCD all the numbers are treated as a binary number converted to decimal output. So BCD output of 0x12 is decimal 18 of became!

Now, your program should read this decimal error, and then output the correct number of decimal. Tip: You can convert back to 18 0x12, and then converted back to 12.

Input format:
input given in row a positive integer in the range [0, 153], can be converted back to ensure that the BCD number is valid, that is to say does not occur when the AF digital convert the integer to a hexadecimal.

Output format:
output a corresponding decimal number.

#include<stdio.h>
int main(){
	int a, b, c;
	
	scanf("%d", &a);
	b = a / 16;
	c = a % 16;
	
	printf("%d", 10*b + c);
	
	return 0;
}

Again a java

import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
        int a,b,c,d;
	        Scanner reader=new Scanner(System.in);
	        a=reader.nextInt();
	        b=a/16;
	        c=a%16;
	        d= 10*b+c;
	        System.out.print(d);
    }
 }
Released seven original articles · won praise 1 · views 119

Guess you like

Origin blog.csdn.net/weixin_45714844/article/details/104088756