首页 > 编程语言 >C# 进制转换帮助类

C# 进制转换帮助类

时间:2024-05-20 21:20:02浏览次数:20  
标签:Convert 转换 进制 C# number int static return public

public static class NumericHelper
{
// 将十进制数转换为二进制字符串
public static string DecimalToBinary(int number)
{
return Convert.ToString(number, 2);
}

// 将十进制数转换为八进制字符串
public static string DecimalToOctal(int number)
{
    return Convert.ToString(number, 8);
}

// 将十进制数转换为十六进制字符串
public static string DecimalToHexadecimal(int number)
{
    return Convert.ToString(number, 16);
}

// 将二进制字符串转换为十进制数
public static int BinaryToDecimal(string binary)
{
    return Convert.ToInt32(binary, 2);
}

// 将八进制字符串转换为十进制数
public static int OctalToDecimal(string octal)
{
    return Convert.ToInt32(octal, 8);
}

// 将十六进制字符串转换为十进制数
public static int HexadecimalToDecimal(string hexadecimal)
{
    return Convert.ToInt32(hexadecimal, 16);
}

}

标签:Convert,转换,进制,C#,number,int,static,return,public
From: https://www.cnblogs.com/yzlong520/p/18202796

相关文章

  • Reflective Journal
    1.process:Inthefirstplace,IfoundaChinesetraditionalstory,Goodorbad,whichiseasytobepresentedinthevideoanddoesnothavecomplicatedcontent.Then,Isearchedsomerelatedpictures.Next,Iwrotescriptanddivideditintosomepartswhic......
  • CLON + QT + CMAKE debug 不打印 (控制台不输出)
    原因:CMAKE设置了WIN32_EXECUTABLETRUE这表示了要生成一个GUI程序,而且WindowsGUI会禁用控制台输出将set_target_properties(aaPROPERTIESWIN32_EXECUTABLETRUE)修改为set_target_properties(aaPROPERTIESWIN32_EXECUTABLEFALSE)或者手动创建控制台:`//未......
  • 「杂题乱刷」CF1973D
    链接算简单题。你发现最大值肯定可以用\(n\)次查出来。然后可以证明\(ans\le\frac{n}{k}\)。总次数为\(n+\frac{n}{k}\timesk\le2n\)。代码:点击查看代码/*Tips:你数组开小了吗?你MLE了吗?你觉得是贪心,是不是该想想dp?一个小时没调出来,是不是该考虑换题?打c......
  • Reflective Journal III
    1.Intheprocessofmakingthisdigitalstory,firstly,IlistedaoutlinetoclearwhatIneed.Secondly,IquestedforsomepicturesandbackgroundmusicontheInternet.Thirdly,Ireadthenarrativewritingandrecordedit.Finally,Imadeavideobyinsertin......
  • reflective journal
    1.Firstofall.Ichosethestoryofthesnailgirlfortextwriting,listedthestoryline.andthenimprovedthestorydetails,LastIselectedsomefragmentstointegrate.andaddedsuitablebackgroundmusictomakethestorymorecompleteandvivid.2......
  • 使用RAG-GPT集成智谱AI、DeepSeek快速搭建OpenAI Cookbook智能客服
    使用RAG-GPT集成智谱AI、DeepSeek快速搭建OpenAICookbook智能客服引言前面介绍了使用RAG-GPT和OpenAI快速搭建LangChain官网智能客服,目前国内也有一些比较不错的云端大模型API服务。本文将介绍通过RAG-GPT集成智谱AI和DeepSeek,快速搭建OpenAICookbook智能客服。RAG技术原理介......
  • 实验5 C语言指针应用编程
    task1_1.c1#include<stdio.h>2#defineN534voidinput(intx[],intn);5voidoutput(intx[],intn);6voidfind_min_max(intx[],intn,int*pmin,int*pmax);78intmain(){9inta[N];10intmin,max;1112print......
  • mit6.828笔记 - lab4 Part C:抢占式多任务和进程间通信(IPC)
    PartC:抢占式多任务和进程间通信(IPClab4到目前为止,我们能够启动多个CPU,让多个CPU同时处理多个进程。实现了中断处理,并且实现了用户级页面故障机制以及写时复制fork。但是,我们的进程调度不是抢占式的,现在每个进程只有在发生中断的时候,才会被调度(调用shed_yeild),这样就有可能会有......
  • C#使用开源操作库MiniExcel操作Excel
    简介MiniExcel简单、高效避免OOM的.NET处理Excel查、写、填充数据工具。目前主流框架大多需要将数据全载入到内存方便操作,但这会导致内存消耗问题,MiniExcel尝试以Stream角度写底层算法逻辑,能让原本1000多MB占用降低到几MB,避免内存不够情况。特点低内存耗用,避免OOM、频繁F......
  • Reflective Journal
    1)Atthebeginningofmyvideoproducing,IwillthinkthatwhichissuitableformystoryandwhatshouldIchoosetodiscuss.Then,it'stimetosortthroughmythoughtsandcomeupwithageneraloutlineofthestory.Forthenextpart,Iamsupposedt......