Blue Bridge Cup-basic exercise-16 Decimal to Binary

Source: Internet
Author: User
Tags decimal to binary

Basic practice hex-to-decimal time limit: 1.0s memory limit: 512.0MBThe problem description enters a positive hexadecimal number string that does not exceed 8 bits from the keyboard, converting it to a positive decimal number after the output.
Note: 10~15 in hexadecimal numbers are denoted by uppercase letters A, B, C, D, E, F, respectively. Sample input FFFF sample output 65535


Seconds to cut the fruit ... (don't know whether to be happy or sad)
Import Java.io.*;import java.util.*;p ublic class main{public static void Main (string[] args) {//TODO auto-generated Metho D stubscanner input = new Scanner (system.in); String str = Input.nextline (), char c[] = Str.tochararray (), Long sum = 0;for (int i = 0; i < c.length; i++) {if (c[i) = ' 0 ' && c[i] <= ' 9 ') {sum + = (c[i]-' 0 ') * MATH.POW (C.length-i-1);} else{sum + = (c[i]-' A ' +) * M Ath.pow (C.length-i-1);}} SYSTEM.OUT.PRINTLN (sum);}}


Blue Bridge Cup-basic exercise-16 Decimal to Binary

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.