-
将十六进制字符串转换为整数的 C#程序
将十六进制字符串转换为整数的 C# 程序
原文:https://www . geesforgeks . org/c-用于将十六进制字符串转换为整数的程序/
给定一个十六进制数作为输入,我们需要编写一个程序将给定的十六进制数转换成等价的整数。要将十六进制字符串转换为整数,我们必须使用 Convert。函数来转换这些值。
语法:
Convert.ToInt32(input_string, Input_base);
这里,
- input_string 是包含字符串格式的十六进制数的输入。
- input_base 是输入值的基数–对于十六进制值,它将是 16。
示例:
Input : 56304
Output : 353028
Input : 598f
Output : 22927
如果我们为例如 672g 输入了错误的值,它会显示错误:输入一个十六进制数:System。格式异常:字符串末尾有其他不可解析的字符。
如果我们输入大于 8 位的数字,例如 746465789,它会显示错误:输入十六进制数:系统。OverflowException:算术运算导致溢出。
节目 1:
C
// C# program to convert array
// of hexadecimal strings to integers
using System;
using System.Text;
class Program {
static void Main(string[] args)
{
// hexadecimal number as string
string input = "56304";
int output = 0;
// converting to integer
output = Convert.ToInt32(input, 16);
// to print the value
Console.WriteLine("Integer number: " + output);
}
}
输出:
Integer number: 353028
节目 2:
C
// C# program to convert array
// of hexadecimal strings
// to integers
using System;
using System.Text;
namespace geeks {
class GFG {
static void Main(string[] args)
{
string input = "";
int output = 0;
try {
// input string
Console.Write("Enter a hexadecimal number: ");
input = Console.ReadLine();
// converting to integer
output = Convert.ToInt32(input, 16);
Console.WriteLine("Integer number: " + output);
}
catch (Exception ex) {
Console.WriteLine(ex.ToString());
}
// hit ENTER to exit
Console.ReadLine();
}
}
}
输入:
598f
输出:
Enter a hexadecimal number:
Integer number: 22927
版权属于:月萌API www.moonapi.com,转载请注明出处
本文链接:https://www.moonapi.com/news/27765.html
栏目列表
最新更新
nodejs爬虫
Python正则表达式完全指南
爬取豆瓣Top250图书数据
shp 地图文件批量添加字段
爬虫小试牛刀(爬取学校通知公告)
【python基础】函数-初识函数
【python基础】函数-返回值
HTTP请求:requests模块基础使用必知必会
Python初学者友好丨详解参数传递类型
如何有效管理爬虫流量?
2个场景实例讲解GaussDB(DWS)基表统计信息估
常用的 SQL Server 关键字及其含义
动手分析SQL Server中的事务中使用的锁
openGauss内核分析:SQL by pass & 经典执行
一招教你如何高效批量导入与更新数据
天天写SQL,这些神奇的特性你知道吗?
openGauss内核分析:执行计划生成
[IM002]Navicat ODBC驱动器管理器 未发现数据
初入Sql Server 之 存储过程的简单使用
SQL Server -- 解决存储过程传入参数作为s
关于JS定时器的整理
JS中使用Promise.all控制所有的异步请求都完
js中字符串的方法
import-local执行流程与node模块路径解析流程
检测数据类型的四种方法
js中数组的方法,32种方法
前端操作方法
数据类型
window.localStorage.setItem 和 localStorage.setIte
如何完美解决前端数字计算精度丢失与数