---
title: "Binary to decimal in FORTRAN"
subject: "Computer Programming"
chapter: 11
key: "semester_1/computer_programming:fortran-binary-to-decimal"
source: https://www.bctengineer.com/q/semester_1/computer_programming/fortran-binary-to-decimal
site: BCT Engineering
---

# Binary to decimal in FORTRAN

Computer Programming · Chapter 11: Programming Language: FORTRAN

- Asked in: 2071 Shrawan, 4 marks
- Answer checked by Claude Opus 5.5 (high effort) on 2026-10-14
- Page: https://www.bctengineer.com/q/semester_1/computer_programming/fortran-binary-to-decimal
- Whole chapter: https://www.bctengineer.com/md/semester_1/computer_programming/chapter-11

## Question

Write the program to convert a binary number to a decimal number using Fortran programming language.

## Short answer

Extract digits with MOD and integer division; accumulate decimal = Σ(digit × 2^position). Verify each digit is 0 or 1. For input 1011, output 11.

## Answer

**Method.** The binary number is read as an integer made of digits 0 and 1 (e.g. 1011). Repeatedly take the last digit with `MOD(N,10)`, multiply by the power of 2 for its position, add it to the decimal value, and remove the digit with `N/10` (integer division). A digit other than 0 or 1 is rejected.

```fortran
      PROGRAM BIN2DEC
      INTEGER N, REM, DEC, P
      PRINT *, 'ENTER A BINARY NUMBER'
      READ *, N
      DEC = 0
      P = 0
   10 IF (N .GT. 0) THEN
         REM = MOD(N, 10)
         IF (REM .GT. 1) THEN
            PRINT *, 'NOT A BINARY NUMBER'
            STOP
         END IF
         DEC = DEC + REM * 2**P
         P = P + 1
         N = N / 10
         GO TO 10
      END IF
      PRINT *, 'DECIMAL VALUE = ', DEC
      STOP
      END
```

**Sample:** N = 1011 gives 1·8 + 0·4 + 1·2 + 1·1 = **11**. N = 11010 gives 16 + 8 + 2 = **26**.

## Check yourself

The answer's key points as multiple-choice questions, with the correct option and why.

1. How does the program get the last digit of the binary number N?
   A. MOD(N,10)
   B. N/10
   C. N*10
   D. MOD(N,2)
   Answer: A. MOD(N,10) gives the remainder when dividing by 10, i.e. the last digit. (Key point: Extract last digit)

2. How is the last digit removed?
   A. N = N - 1
   B. N = N / 10 (integer division)
   C. N = MOD(N,10)
   D. N = N * 10
   Answer: B. Integer division by 10 drops the last digit. (Key point: Remove digit)

3. What is the weight of the digit at position P (counting from 0 at the right)?
   A. 10**P
   B. 2**P
   C. P*2
   D. P+2
   Answer: B. Binary place values are powers of 2, so DEC = DEC + REM * 2**P. (Key point: Weight of digit)

4. What decimal value does N = 11010 give?
   A. 22
   B. 26
   C. 11010
   D. 18
   Answer: B. 16 + 8 + 0 + 2 + 0 = 26. (Key point: Check)

## Related in Computer Programming

- [Decimal to binary conversion](https://www.bctengineer.com/question.md?key=semester_1%2Fcomputer_programming%3Adecimal-to-binary) — Computer Programming, chapter 5
- [Structure of a FORTRAN program](https://www.bctengineer.com/question.md?key=semester_1%2Fcomputer_programming%3Afortran-structure) — Computer Programming, chapter 11, asked 5×
- [Define programming language](https://www.bctengineer.com/question.md?key=semester_1%2Fcomputer_programming%3Adefine-programming-language) — Computer Programming, chapter 1, asked 3×
- [Computer program and programming](https://www.bctengineer.com/question.md?key=semester_1%2Fcomputer_programming%3Adefine-program-programming) — Computer Programming, chapter 2
- [Largest of n numbers in FORTRAN](https://www.bctengineer.com/question.md?key=semester_1%2Fcomputer_programming%3Afortran-largest-n-numbers) — Computer Programming, chapter 11
- [Palindrome check in FORTRAN](https://www.bctengineer.com/question.md?key=semester_1%2Fcomputer_programming%3Afortran-palindrome) — Computer Programming, chapter 11

## Related in other subjects

- [Convert 37.432 decimal to binary](https://www.bctengineer.com/question.md?key=semester_3%2Fdigital_logic%3Aconvert-37-432-binary) — Digital Logic, chapter 1
- [Convert octal 623.77 to decimal, binary, hex](https://www.bctengineer.com/question.md?key=semester_3%2Fdigital_logic%3Aconvert-octal-623-77) — Digital Logic, chapter 1
- [File stream; student binary file program](https://www.bctengineer.com/question.md?key=semester_3%2Fobject_oriented_programming%3Afile-stream-student-binary) — Object Oriented Programming, chapter 8
- [Number conversions 33 to binary etc.](https://www.bctengineer.com/question.md?key=semester_2%2Fbasic_electronics_engineering%3Anumber-conversion-2067-chaitra) — Basic Electronics Engineering, chapter 6
