Continuation of earlier Articles:
Hexadecimal numbers provide yet another way of writing binary values, offering a more compact form than octal numbers. This number system is based on 16 as its radix (or base). Following the general rule of number systems, the Base-16 system has numeral values ranging from 0 to 15 (i.e., one less than the base). Similar to the decimal system, it uses the digits 0 to 9 for the first ten values. For the values 10 to 15, the letters A to F are used as single-digit representations.
Hexadecimal Decimal 0 0 1 1 2 2 3 3 4 4 5 5 6 6 7 7 8 8 9 9 A 10 B 11 C 12 D 13 E 14 F 15
Now, let us see how we can convert binary numbers into hexadecimal form. We will use the same method we have used for converting Binary to Octal form. We have formed groups of 3 binary digits, each with a binary value of 011,111,111 (equivalent to 255 decimal), to find the Octal Number &O377. For a Hexadecimal Number, we must take groups of 4 binary digits (Binary 1111 = (1+2+4+8) = 15, the maximum value of a hexadecimal digit) and add the values of binary bits to find the hexadecimal digit.
For hexadecimal conversion, we instead group the binary digits in sets of four. This works because the largest value represented by four binary digits (1111
) is equal to 15, which corresponds to the highest single-digit value in hexadecimal (F). Once the digits are grouped, simply add the positional values of the binary bits in each group to determine the hexadecimal digit.
Let us find the Hexadecimal value of the Decimal Number 255.
Decimal 255 = Binary 1111,1111 = Hexadecimal digits FF
It takes 3 digits to write the quantity 255 in decimal as well as in Octal 377 (this may not be true when bigger decimal numbers are converted into Octal), but in Hexadecimal it takes only two digits: FF or ff (not case sensitive).
Let us try another example:
Decimal Number 500 = Binary Number 111110100
111,110,100 = Octal Number 764
0001,1111,0100 = Hexadecimal Number 1F4
To identify Octal Numbers, we have used prefix characters &O or &0 with the Number. Similarly, Hexadecimal numbers have &H (not case-sensitive) as the prefix to identify when entered into computers, like &H1F4, &hFF, etc.
You may type Print &H1F4 in the Debug Window and press the Enter Key to convert and print its Decimal Value.
MS-Access Functions
There are only two conversion Functions: Hex() and Oct() in Microsoft Access, both use Decimal Numbers as the parameter.
Try the following Examples, by typing them in the Debug Window to convert a few Decimal Numbers to Octal and Hexadecimal:
? OCT(255) Result: 377 ? &O377 Result: 255 ? HEX(255) Result: FF ? &hFF Result: 255 ? HEX(512) Result: 200 ? &H200 Result: 512
MS-Excel Functions
In Microsoft Excel, there are Functions for converting values to any of these forms. The list of functions is given below:
Simple Usage: X = Application.WorksheetFunction.DEC2BIN(255)
Decimal Value Range -512 to +511 for Binary.
- DEC2BIN()
- DEC2OCT()
- DEC2HEX()
- BIN2DEC()
- BIN2OCT()
- BIN2HEX()
- OCT2DEC()
- OCT2BIN()
- OCT2HEX()
- HEX2DEC()
- HEX2OCT()
- HEX2BIN()
You can convert a Decimal Value to a maximum of 99,999,999 to an Octal Number with the Function DEC2OCT() and its equal value of Octal to Decimal OCT2DEC() Function.
499,999,999,999 is the maximum decimal value for DEC2HEX() and its equal value in Hexadecimal form for HEX2DEC() Function.
With the Binary functions, you can work with the Decimal value range from -512 to 511 up to a maximum of 10 binary digits (1111111111). The left-most bit is the sign bit, i.e., if it is 1, then the value is negative, and 0, positive.
We have created two Excel Functions in Access to convert Decimal Numbers to Binary and Binary Values to Decimal.
But first, you have to attach the Excel Application Object Library file to the Access Object References List.
- Open VBA Window, select References from the Tools Menu, and look for Microsoft Excel Object Library File, and put a check mark to select it.
- Copy the following VBA Code and paste it into a Standard Module:
Public Function DEC2_BIN(ByVal DEC As Variant) As Variant Dim app As Excel.Application Dim obj As Object Set app = CreateObject("Excel.Application") Set obj = app.WorksheetFunction DEC2_BIN = obj.DEC2BIN(DEC) End Function Public Function BIN2_DEC(ByVal BIN As Variant) As Variant Dim app As Excel.Application Dim obj As Object Set app = CreateObject("Excel.Application") Set obj = app.WorksheetFunction BIN2_DEC = obj.Bin2Dec(BIN) End Function
Demo Run from the Debug Window, and the output values are shown below:
? DEC2_BIN(-512) 1000000000 ? DEC2_BIN(-500) 1000001100 ? DEC2_BIN(511) 111111111 ? BIN2_DEC(1000000000) -512 ? BIN2_DEC(111111111) 511
No comments:
Post a Comment
Comments subject to moderation before publishing.