`
wss71104307
  • 浏览: 224404 次
  • 性别: Icon_minigender_1
  • 来自: 南京
社区版块
存档分类
最新评论

Convert a String of hexademical digits into a Int

阅读更多

<<The C programming language>> has an Exercise.

 

Convert a String of hexademical digits into a Int.

#include <stdio.h>
int hexaDecimalToDecimal(char s[])
{

	if(s[0]!='0') return -1;
	if(s[1]!='X' && s[1]!='x') return -1;
	int i=2;
	int sum=0;
	while(s[i]!='\0')
	{

		
	    if(s[i]>='a' && s[i]<='f')  s[i]=s[i]-'a'+10;
		else if(s[i]>='A' && s[i]<='F')  s[i]=s[i]-'A'+10;
		else if(s[i]>='0' && s[i]<='9')  s[i]=s[i]-'0';
		
		sum=sum*16+s[i];

		i++;
	}
	return sum;

}


int main()
{
	char s[]="0xb1A";
	printf("%s",s);
	printf(" 十进制为:%d\n",hexaDecimalToDecimal(s));
	printf("%d",0xb1a);
}

 

 

 

分享到:
评论

相关推荐

    THE MNIST DATABASE of handwritten digits

    The MNIST database of handwritten digits, available from this page, has a training set of 60,000 examples, and a test set of 10,000 examples. It is a subset of a larger set available from NIST. The ...

    A spigot algorithm for digits of pi

    ### Spigot算法用于计算π的数字 #### 引言 在数学领域,尤其是在数值分析与计算机科学交叉的领域中,对于圆周率π的研究一直备受关注。π不仅是一个重要的数学常数,还因其无理性和无限不循环的小数部分而具有...

    POJ1002源代码

    Each telephone number consists of a string composed of decimal digits, uppercase letters (excluding Q and Z) and hyphens. Exactly seven of the characters in the string will be digits or letters.

    Computation of 2700 billion decimal digits of Pi using a Desktop Computer

    S(a,b)=\sum_{n=a}^{b-1} \frac{a_n}{\prod_{k=a}^{n} g(k)} \cdot \prod_{k=a}^{n} q(k) \] 其中, - \(G(a,b)=\prod_{k=a}^{b-1} g(k)\) - \(Q(a,b)=\prod_{k=a}^{b-1} q(k)\) - \(P(a,b)\)使得\(S(a,b)=\frac{P...

    Count the frequency distribution of units digits

    Count the frequency distribution of units digits

    MNIST 手写数字图像数据集

    The MNIST database of handwritten digits, has a training set of 60,000 examples, and a test set of 10,000 examples. It is a subset of a larger set available from NIST. The digits have been size-...

    Pi: A Source Book第三版

    There is a substantial exposition of the recent history of the computation of digits of pi, a discussion of the normality of the distribution of the digits, and new translations of works by Viete and...

    Pi: A Source Book, 1rd edition

    There is a substantial exposition of the recent history of the computation of digits of pi, a discussion of the normality of the distribution of the digits, and new translations of works by Viete and...

    Pi: A Source Book, 2rd edition

    There is a substantial exposition of the recent history of the computation of digits of pi, a discussion of the normality of the distribution of the digits, and new translations of works by Viete and...

    Pi: A Source Book, 3rd edition

    There is a substantial exposition of the recent history of the computation of digits of pi, a discussion of the normality of the distribution of the digits, and new translations of works by Viete and...

    SumOfDigits.java

    SumOfDigits.java

    NumberOfDigits.java

    NumberOfDigits.java

    MNIST Database of Handwritten Digits for MATLAB.zip

    这个压缩包“MNIST Database of Handwritten Digits for MATLAB.zip”显然包含了专门为MATLAB环境设计的工具和数据,使得用户可以在MATLAB中方便地进行MNIST数据集的加载和处理。 首先,MNIST数据集本身包含60,000...

    pku3720 Occurrence of Digits (上传个东西累呢。。。)

    描述水题的细节问题。 不会就看,这题没什么技术含量.

    Pi : a sourcebook on the recent history of Pi and its computation Book Cover

    ”), articles presenting new and often amazing techniques for computing digits of pi (e.g., the “BBP” algorithm for pi, which permits one to compute an arbitrary binary digit of pi without needing ...

    oj题目:电话号码匹配

    Each telephone number consists of a string composed of decimal digits, uppercase letters (excluding Q and Z) and hyphens. Exactly seven of the characters in the string will be digits or letters. ...

    Java实现任意进制的转换

    private static String toBase36String(int[] digits) { // 实现细节... } ``` 这里的关键是将36进制数转换为十进制数组进行加法运算,然后将结果再次转换回36进制。 以上就是Java实现任意进制转换的方法,包括二...

    编译原理龙书答案

    any string derived from the grammar can be considered to be a sequence consisting of 11, 1001 and 0, and not prefixed with 0. the sum of this string is: sum = Σn (21 + 20) * 2 n + Σm (23 + 20) * 2m ...

Global site tag (gtag.js) - Google Analytics