2016 Blue Bridge Cup basic training--Decimal conversion hex

Source: Internet
Author: User
Decimal conversion hexadecimal problem Description The hexadecimal number is a representation of an integer that is often used in programming. It has 0,1,2,3,4,5,6,7,8,9,a,b,c,d,e,f a total of 16 symbols, representing 0 to 15 of the decimal number. The hexadecimal count method is 16 in 1, so the decimal number 16 in hexadecimal is 10, while the decimal 17 in hexadecimal is 11, and so on, the decimal 30 in hexadecimal is 1 E.
A nonnegative integer is given, which is represented as a 16-binary form. Input format input contains a non-negative integer A that represents the number to convert. 0<=a<=2147483647 output Format Output 16 binary representation of this integer example input 30 sample output 1E
Code:
Import Java.util.Scanner;

public class Main {public
	static void Main (string[] args) throws Exception {
		Scanner in = new Scanner (system.in);
		Long a = In.nextlong ();
		Char[] B = new char[10000001];
		int i = 0;
		if (a==0)
			System.out.println (0);
		while (A! = 0) {
			int t = (int) (A%16);
			If (a% >= 0 && a% <= 9) {
				b[i++] = (char) (' 0 ' +t);
			}
			else {
				if (a%16>=10&&a%16<=15)
					b[i++]= (char) (' a ' +t-10);
			}
			a/=16;
		}
		for (int j = i-1; j>=0; j--)
			System.out.print (B[j]);
	}
}


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.