# Program code for hexadecimal to decimal conversion

### Write a c program to convert a hexadecimal number to decimal

You can use char*_itoa(intvalue,char*string,intradix) in <stdlib.h>; to convert an integer to a string in other binary

Reference code:

#include<stdio.h>

#include<stdlib.h> //include header file for _itoa

int main()

{

int a=110;

char p[20];

< p> _itoa(110,p,16); //16 means hexadecimal, can also use 2,8,10

printf(“%s”,p);

return 0;

}

### VB in hexadecimal and decimal conversion of each other, how to deal with

10 to hexadecimal then you can use the HEX () function, hexadecimal to 10 there is no existing function, you can use the following code to achieve:

‘ Output: HEX_to_DEC (decimal number)

‘ ‘ Input data type: String

‘ Output: HEX_to_DEC(Decimal number)

‘ Output data type: Long

‘ Maximum number of input is 7FFFFFFF,Maximum number of output is 2147483647

Public Function HEX_to_DEC(ByVal Hex_to_DEC(ByVal Hex number)

‘ Purpose: To convert hex to decimal

‘ Input: Hex(hex number)

‘ DEC(ByVal Hex As String) As Long

Dim i As Long

Dim B As Long

Hex = UCase(Hex)

For i = 1 To Len(Hex)

Select Case Mid(Hex, Len(Hex ) – i + 1, 1)

Case “0”: B = B + 16 ^ (i – 1) * 0

Case “1”: B = B + 16 ^ (i – 1) * 1

Case “2”: B = B + 16 ^ (i – 1) * 2

Case “3”: B = B + 16 ^ (i – 1) * 3

Case “3”: B = B + 16 ^ (i – 1) * 3

Case “5”: B = B + 16 ^ (i – 1) * 5

Case “6”: B = B + 16 ^ (i – 1) * 6

Case “7”: B = B + 16 ^ (i – 1) * 7

Case “8”: B = B + 16 ^ (i – 1) * 7

Case “8”: B = B + 16 ^ (i – 1) * 2

Case “8”: B = B + 16 ^ (i – 1) * 8

Case “9”: B = B + 16 ^ (i – 1) * 9

Case “A”: B = B + 16 ^ (i – 1) * 10

Case “B”: B = B + 16 ^ (i – 1) * 11

Case “C”: B = B + 16 ^ (i – 1) * 12< /p>

Case “D”: B = B + 16 ^ (i – 1) * 13

Case “E”: B = B + 16 ^ (i – 1) * 14

Case “F”: B = B + 16 ^ (i – 1) * 15

End Select

Next i

HEX_to _DEC = B

End Function

Expansion:

Function to convert Decimal to Hexadecimal in VB:

Input: Dec(Decimal)’

Input datatype: Long’

Output: D2H(Hex)’< /p>

Output data type: string’

Maximum number of inputs is 2147483647,

Maximum number of outputs is 7FFFFFFFPublicFunctionD2H(DecAsLong)AsString

DimaAsString

D2H=””

DoWhileDec>0

a=CStr(DecMod16) SelectCasea Case “10”:a=”A”

Case “11”:a=”B”

Case “12”:a=”C”

Case” 13″:a=”D”

Case “14”:a=”E”

Case “15”:a=”F”

EndSelect

D2H=a&D2H

Dec=Dec\16 LoopEndFunction

### How to write a hex to decimal program in C?

This is very simple:

# include <stdio.h>

int main(void)

{

int var;

printf(“%d”, var);// output var in decimal

return 0;

}

### C write a function, hexadecimal to decimal

C language hexadecimal to decimal specific function is as follows:

#include “stdio.h”

intmain()

{

intnum=0;

inta[100];

inti=0;

intm=0;

intyushu;

charhex[16]={‘0′,’1′,’2′,’3′,’4′,’5′,’6′,’7′,’8′,’9′,’A’,’B’,’C’,’D’,’E’,’F’};

scanf(“%d”,&num);

while(num>0)

{

yushu=num%16;

a[i++]=yushu;

num =num/16;

}

printf(“The number converted to hex is: 0x”);

for(i=i-1;i>=0;i–)//output in reverse order

{

m=a[i];

printf(“%c”,hex[m]) )

}

printf(“\n”);

}

C is a general-purpose computer programming language with a wide range of applications.The design goal of C was to provide a programming language that could be compiled in an easy manner, handle low-level memory, produce a small amount of machine code, and run without any runtime environment support.