I have a variable which contains a binary value. I need to convert it to a decimal value.
Please let me know if we have an intrinsic function in COBOL to do this.
If not can you please give me a small logic to do the same.
Joined: 22 Apr 2006 Posts: 6258 Location: Mumbai, India
First, are you wanting to display the decimal equivalent of some Binary number or just the Decimal value of digits in Binary? Example: the binary for '1' is 0001, '2' is 0010, etc. This is VERY different from the Binary for 12345, for example?
Either way, you convert from a number base by dividing by the number base, using the remainder as the digit position, from right to left in the result and looping until the quotient is zero. You do the inverse to go the other way.
Another way would be to use a table with the decimal digits encoded as binary literals, but this only works on a digit basis and not a logical number base.
And why COBOL functions looks like a choice to you?