# How to convert one number system to another number system in Excel

Asked By 10 points N/A Posted on -

I am using Microsoft Excel 2000. I faced a problem. Itâ€™s a conversation from one number system to another number system. Suppose, I have a binary number like this 1100100.

I want to convert this number to a decimal number.

Is there any Excel formula to convert one number system to another number system?

SHARE
Best Answer by zicooo82
Answered By 0 points N/A #115842

## How to convert one number system to another number system in Excel

Yes, there are some built in functions in the Excel by which you can easily convert one form of number system to another form some of the functions are as follows

==> Â =BIN2HEX

==>Â  =BIN2OCT

==>Â  =BIN2DEC

==> =Â DEC2BIN

==> =DEC2HEX

etc. For example if you want to convert a binary number to octal number you can write the following in an Excel cell:

=BIN2OCT(1011,3)

The above command will convert the binary number 1011 to octal numbers having three characters. The sign '=' before the function name tells the application that aÂ builtinÂ function is going to used. So please do not ignore the '+' sign before the function name.

Answered By 0 points N/A #115844

## How to convert one number system to another number system in Excel

1. Open Excel.
Â
2. Press ALT+F11.
Â
3. Right Click on This workbook and choose insert module.
Â
4. Copy and paste the following codes into the module:
Â
Function BinToDec(D As String) As String
Â  Â  Dim N As Long
Â  Â  Dim Res As Long
Â  Â  For N = Len(D) To 1 Step -1
Â  Â  Â  Â  Res = Res + ((2 ^ (Len(D) â€“ N)) * CLng(Mid(D, N, 1)))
Â  Â  Next N
Â  Â  BinToDec = Str(Res)
End Function
Â
Function DecToBin(D As String) As String
Â  Â  Dim N As Long
Â  Â  Dim Res As String
Â  Â  For N = 31 To 1 Step -1
Â  Â  Â  Â  Res = Res & IIf(CLng(D) And 2 ^ (N â€“ 1), "1", "0")
Â  Â  Next N
Â  Â  N = InStr(1, Res, "1")
Â  Â  DecToBin = Mid(Res, IIf(N > 0, N, Len(Res)))
End Function
Â
Â
Option Explicit
Â
Public Function HexToDec(Hex As String) As Double
Â  Â Â
Â  Â  Dim i Â  Â  Â  Â  Â  Â  Â  As Long
Â  Â  Dim j Â  Â  Â  Â  Â  Â  Â  As Variant
Â  Â  Dim k Â  Â  Â  Â  Â  Â  Â  As Long
Â  Â  Dim n Â  Â  Â  Â  Â  Â  Â  As Long
Â  Â  Dim HexArray() Â  Â  Â As Double
Â  Â Â
Â  Â  n = Len(Hex)
Â  Â  k = -1
Â  Â  ReDim HexArray(1 To n)
Â  Â  For i = n To 1 Step -1 j = Mid(Hex, i, 1) k = k + 1 Select Case j
Â  Â  Â  Â  Case 0 To 9
Â  Â  Â  Â  Â  Â  HexArray(i) = j * 16 ^ (k)
Â  Â  Â  Â  Case Is = "A"
Â  Â  Â  Â  Â  Â  HexArray(i) = 10 * 16 ^ (k)
Â  Â  Â  Â  Case Is = "B"
Â  Â  Â  Â  Â  Â  HexArray(i) = 11 * 16 ^ (k)
Â  Â  Â  Â  Case Is = "C"
Â  Â  Â  Â  Â  Â  HexArray(i) = 12 * 16 ^ (k)
Â  Â  Â  Â  Case Is = "D"
Â  Â  Â  Â  Â  Â  HexArray(i) = 13 * 16 ^ (k)
Â  Â  Â  Â  Case Is = "E"
Â  Â  Â  Â  Â  Â  HexArray(i) = 14 * 16 ^ (k)
Â  Â  Â  Â  Case Is = "F"
Â  Â  Â  Â  Â  Â  HexArray(i) = 15 * 16 ^ (k)
Â  Â  Â  Â  End Select
Â  Â  Next i
Â  Â  HexToDec = Application.WorksheetFunction.Sum(HexArray)
Â  Â Â
End Function
Â
Option Explicit
Â
Public Function DecToHex(Dec As Double) As String
Â  Â Â
Â  Â  Dim i Â  Â  Â  Â  Â  Â  Â  As Long
Â  Â  Dim n Â  Â  Â  Â  Â  Â  Â  As Long
Â  Â  Dim PlaceValHex Â  Â  As Long
Â  Â  Dim Hex(1 To 256) Â  As String
Â  Â  Dim HexTemp Â  Â  Â  Â  As String
Â  Â  Dim Divisor Â  Â  Â  Â  As Long
Â  Â Â
Â  Â  Dec = Int(Dec)
Â  Â Â
Â  Â  For i = 256 To 2 Step -1
Â  Â  Â  Â  If Dec >= 16 ^ (i â€“ 1) And Dec > 15 Then
Â  Â  Â  Â  Â  Â  PlaceValHex = Int(Dec / (16 ^ (i â€“ 1)))
Â  Â  Â  Â  Â  Â  Dec = Dec â€“ (16 ^ (i â€“ 1)) * PlaceValHex
Â  Â  Â  Â  Â  Â  Select Case PlaceValHex
Â  Â  Â  Â  Â  Â  Case 0 To 9
Â  Â  Â  Â  Â  Â  Â  Â  Hex(i) = CStr(PlaceValHex)
Â  Â  Â  Â  Â  Â  Case Is = 10
Â  Â  Â  Â  Â  Â  Â  Â  Hex(i) = "A"
Â  Â  Â  Â  Â  Â  Case Is = 11
Â  Â  Â  Â  Â  Â  Â  Â  Hex(i) = "B"
Â  Â  Â  Â  Â  Â  Case Is = 12
Â  Â  Â  Â  Â  Â  Â  Â  Hex(i) = "C"
Â  Â  Â  Â  Â  Â  Case Is = 13
Â  Â  Â  Â  Â  Â  Â  Â  Hex(i) = "D"
Â  Â  Â  Â  Â  Â  Case Is = 14
Â  Â  Â  Â  Â  Â  Â  Â  Hex(i) = "E"
Â  Â  Â  Â  Â  Â  Case Is = 15
Â  Â  Â  Â  Â  Â  Â  Â  Hex(i) = "F"
Â  Â  Â  Â  Â  Â  End Select
Â  Â  Â  Â  Else
Â  Â  Â  Â  Â  Â  Hex(i) = "0"
Â  Â  Â  Â  End If
Â  Â  Next i
Â  Â  PlaceValHex = Dec
Â  Â  Select Case PlaceValHex
Â  Â  Case 0 To 9
Â  Â  Â  Â  Hex(1) = CStr(PlaceValHex)
Â  Â  Case Is = 10
Â  Â  Â  Â  Hex(1) = "A"
Â  Â  Case Is = 11
Â  Â  Â  Â  Hex(1) = "B"
Â  Â  Case Is = 12
Â  Â  Â  Â  Hex(1) = "C"
Â  Â  Case Is = 13
Â  Â  Â  Â  Hex(1) = "D"
Â  Â  Case Is = 14
Â  Â  Â  Â  Hex(1) = "E"
Â  Â  Case Is = 15
Â  Â  Â  Â  Hex(1) = "F"
Â  Â  End Select
Â  Â  For i = 256 To 1 Step -1
Â  Â  Â  Â  If Hex(i) = "0" Then
Â  Â  Â  Â  Else
Â  Â  Â  Â  Â  Â  n = i
Â  Â  Â  Â  Â  Â  Exit For
Â  Â  Â  Â  End If
Â  Â  Next i
Â  Â  For i = n To 1 Step -1
Â  Â  Â  Â  HexTemp = HexTemp & Hex(i)
Â  Â  Next i
Â  Â  DecToHex = HexTemp
Â  Â Â
End Function
Â
5. Press ALT+F11
Â
6. Choose user defined from functions category pop-up list.
Â
7. You will find 4 new functions helps you to convert from binary to decimal and vice versa, also from hex to dec and vice versa.
Â
8. You can save it as Excel Add-in and attach to file in the Excel add-in to make it part of your Excel.