Basic Practice hex to Decimal

Source: Internet
Author: User
Tags hex to decimal

----------------------------------------------------------------------------------------

It seems that the int type will not exceed, but ...

----------------------------------------------------------------------------------------

Algorithm

1 /*Problem Description2 Enter a positive hexadecimal number string that does not exceed 8 bits from the keyboard, converting it to a positive decimal number after the output. 3 Note: 10~15 in hexadecimal numbers are denoted by uppercase letters A, B, C, D, E, F, respectively. 4 Sample Input5 FFFF6 Sample Output7 65535*/8 ImportJava.util.*;9  Public classMain {Ten      Public Static voidMain (string[] args) { OneString st =NewScanner (system.in). nextline (); ASystem.out.println (Long.parselong (St, 16)); -     } -}

Learning Supplement

Integer class

static int parseint (String s)//将字符串参数作为有符号的十进制整数进行解析

static int parseint (String s,int radix)//resolves the string argument to a signed integer using the cardinality specified by the second parameter. Returns a decimal integer (radix represents a binary)

Example:

parseint ("0", 10) returns 0

parseint ("473", 10) returns 473

parseint ("0", 10) returns 0

parseint ("-ff", 16) return-255

parseint ("1100110", 2) returns 102

parseint ("2147483647", 10) returns 2147483647

parseint ("2147483648", 10) return-2147483648

parseint ("2147483648", 10) throws NumberFormatException

parseint ("99", 8) throws NumberFormatException

parseint ("Kona", 10) throws NumberFormatException

parseint ("Kona", 27) return 411787

Long class

Static Long Parselong (string s)//resolves the String argument to a signed decimallong

Static Long Parselong (String s,int radix)//resolves the String parameter to a signed long , cardinality specified by the second parameter returns a decimal long

Basic Practice hex to Decimal

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.