展开全部
//C语言实现:
#include<stdio.h>
void main()
{char b[]="0123456789ABCDEF";
long int n,x;
int i,a[40];
printf("\n Please input n=");
scanf("%ld",&n);
x=n;i=0;
while(x>0)
{a[i]=x%16;
x=x/16;
i++;
}
while(i>0)
{printf("%c",b[a[i-1]]);
i--;
}
printf("\n");
}
对于大数转换可以用如下程序:
#include "Stdio.h"
#include "Conio.h"
char result[100];
int pos;
void change(int *num);
int main(void)
{
char str[100];
int num[100];
int bin[300]={0};
int quot[100],residue=0;
int i,j,k=0,suffix=0,index=0;
puts("Input a decimal number:");
gets(str);
for(i=0;i<strlen(str);num[i]=str[i]-48,i++);
j=i-1;
while(j>=0)
{
num[j]%2?(bin[k++]=1):(bin[k++]=0);
while(index<=j)
{
residue+=num[index];
if(residue>=2)
quot[suffix++]=residue/2;
else if(index)
quot[suffix++]=0;
residue=(num[index]%2)*10;
index++;
}
for(i=0;i<suffix;num[i]=quot[i],i++);
j=suffix-1;
residue=suffix=index=0;
}
for(i=0;i<k;change(bin+i),i+=4);
for(i=pos-1;i>=0;printf("%c",result[i]),i--);
getch();
return 0;
}
void change(int *num)
{
if(num[3]==0&&num[2]==0&&num[1]==0&&num[0]==0)
sprintf(result+pos,"%c",'0');
if(num[3]==0&&num[2]==0&&num[1]==0&&num[0]==1)
sprintf(result+pos,"%c",'1');
if(num[3]==0&&num[2]==0&&num[1]==1&&num[0]==0)
sprintf(result+pos,"%c",'2');
if(num[3]==0&&num[2]==0&&num[1]==1&&num[0]==1)
sprintf(result+pos,"%c",'3');
if(num[3]==0&&num[2]==1&&num[1]==0&&num[0]==0)
sprintf(result+pos,"%c",'4');
if(num[3]==0&&num[2]==1&&num[1]==0&&num[0]==1)
sprintf(result+pos,"%c",'5');
if(num[3]==0&&num[2]==1&&num[1]==1&&num[0]==0)
sprintf(result+pos,"%c",'6');
if(num[3]==0&&num[2]==1&&num[1]==1&&num[0]==1)
sprintf(result+pos,"%c",'7');
if(num[3]==1&&num[2]==0&&num[1]==0&&num[0]==0)
sprintf(result+pos,"%c",'8');
if(num[3]==1&&num[2]==0&&num[1]==0&&num[0]==1)
sprintf(result+pos,"%c",'9');
if(num[3]==1&&num[2]==0&&num[1]==1&&num[0]==0)
sprintf(result+pos,"%c",'A');
if(num[3]==1&&num[2]==0&&num[1]==1&&num[0]==1)
sprintf(result+pos,"%c",'B');
if(num[3]==1&&num[2]==1&&num[1]==0&&num[0]==0)
sprintf(result+pos,"%c",'C');
if(num[3]==1&&num[2]==1&&num[1]==0&&num[0]==1)
sprintf(result+pos,"%c",'D');
if(num[3]==1&&num[2]==1&&num[1]==1&&num[0]==0)
sprintf(result+pos,"%c",'E');
if(num[3]==1&&num[2]==1&&num[1]==1&&num[0]==1)
sprintf(result+pos,"%c",'F');
pos++;
}
#include<stdio.h>
void main()
{char b[]="0123456789ABCDEF";
long int n,x;
int i,a[40];
printf("\n Please input n=");
scanf("%ld",&n);
x=n;i=0;
while(x>0)
{a[i]=x%16;
x=x/16;
i++;
}
while(i>0)
{printf("%c",b[a[i-1]]);
i--;
}
printf("\n");
}
对于大数转换可以用如下程序:
#include "Stdio.h"
#include "Conio.h"
char result[100];
int pos;
void change(int *num);
int main(void)
{
char str[100];
int num[100];
int bin[300]={0};
int quot[100],residue=0;
int i,j,k=0,suffix=0,index=0;
puts("Input a decimal number:");
gets(str);
for(i=0;i<strlen(str);num[i]=str[i]-48,i++);
j=i-1;
while(j>=0)
{
num[j]%2?(bin[k++]=1):(bin[k++]=0);
while(index<=j)
{
residue+=num[index];
if(residue>=2)
quot[suffix++]=residue/2;
else if(index)
quot[suffix++]=0;
residue=(num[index]%2)*10;
index++;
}
for(i=0;i<suffix;num[i]=quot[i],i++);
j=suffix-1;
residue=suffix=index=0;
}
for(i=0;i<k;change(bin+i),i+=4);
for(i=pos-1;i>=0;printf("%c",result[i]),i--);
getch();
return 0;
}
void change(int *num)
{
if(num[3]==0&&num[2]==0&&num[1]==0&&num[0]==0)
sprintf(result+pos,"%c",'0');
if(num[3]==0&&num[2]==0&&num[1]==0&&num[0]==1)
sprintf(result+pos,"%c",'1');
if(num[3]==0&&num[2]==0&&num[1]==1&&num[0]==0)
sprintf(result+pos,"%c",'2');
if(num[3]==0&&num[2]==0&&num[1]==1&&num[0]==1)
sprintf(result+pos,"%c",'3');
if(num[3]==0&&num[2]==1&&num[1]==0&&num[0]==0)
sprintf(result+pos,"%c",'4');
if(num[3]==0&&num[2]==1&&num[1]==0&&num[0]==1)
sprintf(result+pos,"%c",'5');
if(num[3]==0&&num[2]==1&&num[1]==1&&num[0]==0)
sprintf(result+pos,"%c",'6');
if(num[3]==0&&num[2]==1&&num[1]==1&&num[0]==1)
sprintf(result+pos,"%c",'7');
if(num[3]==1&&num[2]==0&&num[1]==0&&num[0]==0)
sprintf(result+pos,"%c",'8');
if(num[3]==1&&num[2]==0&&num[1]==0&&num[0]==1)
sprintf(result+pos,"%c",'9');
if(num[3]==1&&num[2]==0&&num[1]==1&&num[0]==0)
sprintf(result+pos,"%c",'A');
if(num[3]==1&&num[2]==0&&num[1]==1&&num[0]==1)
sprintf(result+pos,"%c",'B');
if(num[3]==1&&num[2]==1&&num[1]==0&&num[0]==0)
sprintf(result+pos,"%c",'C');
if(num[3]==1&&num[2]==1&&num[1]==0&&num[0]==1)
sprintf(result+pos,"%c",'D');
if(num[3]==1&&num[2]==1&&num[1]==1&&num[0]==0)
sprintf(result+pos,"%c",'E');
if(num[3]==1&&num[2]==1&&num[1]==1&&num[0]==1)
sprintf(result+pos,"%c",'F');
pos++;
}
TableDI
2024-07-18 广告
2024-07-18 广告
当我们谈到Python与Excel的拆分时,通常指的是使用Python的库来读取Excel文件中的数据,然后根据某种逻辑(如按行、按列、按特定值等)将数据拆分成多个部分或输出到新的Excel文件中。上海悉息信息科技有限公司在处理这类任务时,...
点击进入详情页
本回答由TableDI提供
展开全部
create function hex(@cardno int )
returns varchar(100)
as
begin
declare @temp_mod int
declare @i int
declare @result varchar(100)
declare @temp_x int
declare @result_values int
set @result=''
set @i=1
set @temp_x=0
while @cardno>0
begin
set @temp_mod=@cardno%16
set @cardno=@cardno/16
set @result=(case @temp_mod when 10 then 'A'
when 11 then 'B'
when 12 then 'C'
when 13 then 'D'
when 14 then 'E'
when 15 then 'F'
when 16 then 'G'
when 17 then 'H'
when 18 then 'I' else ltrim(str(@temp_mod)) end )+@result
end
--以上是把十进制转成十六进制
if len(@result)>=6
set @result=right(@result,6)
while len(@result)-@i>=0
begin
set @temp_x=(case len(@result)-@i when 1 then 16
when 2 then 16*16
when 3 then 16*16*16
when 4 then 16*16*16*16
when 5 then 16*16*16*16*16
when 6 then 16*16*16*16*16*16
when 7 then 16*16*16*16*16*16*16
when 8 then 16*16*16*16*16*16*16*16 else 1 end )
set @result_values=@result_values+(case substring(@result,@i,1) when 'A' then 10
when 'B' then 11
when 'C' then 12
when 'D' then 13
when 'E' then 14
when 'F' then 15
when 'G' then 16
when 'H' then 17
when 'I' then 18
else substring(@result,@i,1) end)*@temp_x
set @i=@i+1
end
--以上是把十六进制转成十进制
returns varchar(100)
as
begin
declare @temp_mod int
declare @i int
declare @result varchar(100)
declare @temp_x int
declare @result_values int
set @result=''
set @i=1
set @temp_x=0
while @cardno>0
begin
set @temp_mod=@cardno%16
set @cardno=@cardno/16
set @result=(case @temp_mod when 10 then 'A'
when 11 then 'B'
when 12 then 'C'
when 13 then 'D'
when 14 then 'E'
when 15 then 'F'
when 16 then 'G'
when 17 then 'H'
when 18 then 'I' else ltrim(str(@temp_mod)) end )+@result
end
--以上是把十进制转成十六进制
if len(@result)>=6
set @result=right(@result,6)
while len(@result)-@i>=0
begin
set @temp_x=(case len(@result)-@i when 1 then 16
when 2 then 16*16
when 3 then 16*16*16
when 4 then 16*16*16*16
when 5 then 16*16*16*16*16
when 6 then 16*16*16*16*16*16
when 7 then 16*16*16*16*16*16*16
when 8 then 16*16*16*16*16*16*16*16 else 1 end )
set @result_values=@result_values+(case substring(@result,@i,1) when 'A' then 10
when 'B' then 11
when 'C' then 12
when 'D' then 13
when 'E' then 14
when 'F' then 15
when 'G' then 16
when 'H' then 17
when 'I' then 18
else substring(@result,@i,1) end)*@temp_x
set @i=@i+1
end
--以上是把十六进制转成十进制
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
public class Convert{
public static void main(String[] args){
System.out.println(toHex(12345));
}
public static String toHex(int x){
String result="";
while(x>0){
result=(char)(x%16>9?x%16+55:x%16+48)+result;
x/=16;
}
return result;
}
}
public static void main(String[] args){
System.out.println(toHex(12345));
}
public static String toHex(int x){
String result="";
while(x>0){
result=(char)(x%16>9?x%16+55:x%16+48)+result;
x/=16;
}
return result;
}
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询