Continuation of earlier Articles:
Hexadecimal Numbers are yet another method to write Binary Values into shorter forms than Octal Numbers. This Number System has the Number 16 as its Base. As per the basic rules, which we are following to devise new Number Systems, the Base-16 Number System has its Numeral values from 0 to 15 (i.e., one less than the base value 16). Like the decimal number system, the hexadecimal number system also has digit values from 0 to 9. Since there are no single digit values for 10 to 15 the alphabets A to F are used.
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 made groups of 3 binary digits of binary value 011,111,111 (equal to 255 decimal) to find the Octal Number &O377. For Hexadecimal Number, we must take groups 4 binary digits (Binary 1111 = (1+2+4+8) = 15, the maximum value of a hexadecimal digit) and add the values of binary digits to find the hexadecimal digit.
Let us find the Hexadecimal value of 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 Debug Window and press Enter Key to covert 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 Decimal Value to a maximum of 99,999,999 to 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 when 0 is 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 xx.0 Object Library File, and put a checkmark 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.