Go: package main

import (
	"bufio"
	"os"
	"strconv"
	"math"
	"fmt"
)

var scanner = bufio.NewScanner(os.Stdin)

func main() {
	two := make([]float64, 12)
	flag := make([]int, 12)
	for i := 0; i < 12; i++ {
		two[i] = math.Pow(2.0, 7.0-float64(i))
	}
	for scanner.Scan() {
		n, _ := strconv.ParseFloat(scanner.Text(), 64)
		if n < 0 {
			break
		}
		for i := 0; i < 12; i++ {
			flag[i] = 0
			if n >= two[i] {
				n -= two[i]
				flag[i] = 1
			}
		}
		if n < 10e-10 {
			i := 0
			for i < 12 {
				fmt.Printf("%d", flag[i])
				if i == 7 {
					fmt.Printf(".")
				}
				i++
			}
			fmt.Printf("\n")
		} else {
			fmt.Println("NA")
		}
	}
}

C++: #include<iostream>
#include<string>
using namespace std;

int main() {
  double d;
  while(cin>>d) {
    if(d < 0) break;
    int di = (int)d;
    if(di >= 1<<9) {
      cout<<"NA"<<endl;
      continue;
    }
    d *= 16;
    if(d - (int)d > 0) {
      cout<<"NA"<<endl;
      continue;
    }
    di = (int)d;
    string res = "";
    while(di > 0) {
      if(di%2) res = "1"+res;
      else res = "0"+res;
      di /= 2;
    }

    if(res.length() < 12) res = string(12-res.length(), '0') + res;
    for(int i=0; i<12; ++i) {
      cout<<res[i];
      if(i == 7) cout<<".";
    }
    cout<<endl;
  }
}

C++: #include<iostream>

double n;
char ans[14];
double tw[4]={0.5,0.25,0.125,0.0625};

void solve(){
	bool flag = false;
	int tmp = n;
	for(int i=7; i>=0; i--){
		ans[i] = (char)(tmp%2+48);
		tmp = tmp/2;
	}
	if(tmp != 0)
		flag = true;
	ans[8] = '.';
	double temp = n-(int)n;
	for(int i=9; i<=12; i++){
		if(temp-tw[i-9]>=0){
			ans[i] = '1';
			temp -= tw[i-9];
		}else
			ans[i] = '0';
	}
	if(temp != 0 || flag)
		std::cout << "NA\n";
	else
		std::cout << ans << std::endl;
}

int main(){
	while(true){
		std::cin>> n;
		if(n<0)
			return 0;
		solve();
	}
}

C++: #include <iostream>
#include <cmath>
#include <algorithm>
 
using namespace std;
 
int main()
{
    double n;
 
    while (cin >> n, n >= 0) {
	string ans, tmp;
	int integer = n;
 
	n -= integer;
 
	while (integer) {
	    tmp += (integer % 2) + '0';
	    integer /= 2;
	}
 
	int len = (int)tmp.size();
	for (int i = len; i < 8; i++) {
	    tmp += "0";
	} 
 
	reverse(tmp.begin(), tmp.end());
	ans += tmp + ".";
 
	tmp = "";
 
	for (int i = 0; i < 4; i++) {
	    double b = pow(2.0, -(i+1));
 
	    if (n == b) {  
		tmp += "1";
		n -= b;
		break;
	    }
 
	    if ((int)(n / b) == 0) {
		tmp += "0";
	    } else {
		tmp += "1";
		n -= b;
	    }
	}
 
	len = (int)tmp.size();
	for (int i = len; i < 4; i++) {
	    tmp += "0";
	}  
 
	if (!n) cout << ans + tmp << endl;
	else cout << "NA" << endl;
    }
    return 0;
}

C++: /* AOJ 0220 Binary Digit A Doctor Loved */

#include <iostream>

using namespace std;

void print_binary_digits(double x);

int
main()
{
    for (;;) {
        double x;

        cin >> x;
        if (x < 0) break;

        print_binary_digits(x);
    }

    return 0;
}

void
print_binary_digits(double x)
{
    int x_i = (int)x;
    double x_f = x - x_i;
    int digits[12] = {0};
    double b = 0.5;
    int i;

    try {
        // 整数部分
        for (i = 0; i < 8 && x_i > 0; i++) {
            digits[7 - i] = x_i & 1;
            x_i >>= 1;
        }
        if (x_i) throw 0;

        // 小数部分
        for (i = 0; i < 4 && x_f > 0; i++) {
            if (x_f >= b) {
                digits[8 + i] = 1;
                x_f -= b;
            }

            b /= 2;
        }
        if (x_f) throw 0;

        for (i = 0; i < 8; i++)
            cout << digits[i];
        cout << '.';
        for (i = 8; i < 12; i++)
            cout << digits[i];

        cout << endl;
    } catch (...) {
        cout << "NA" << endl;
    }
}

C++: #include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <ctime>
#include <cassert>
#include <iostream>
#include <cctype>
#include <sstream>
#include <string>
#include <list>
#include <vector>
#include <queue>
#include <set>
#include <stack>
#include <map>
#include <utility>
#include <numeric>
#include <algorithm>
#include <iterator>
#include <bitset>
#include <complex>
#include <fstream>
#include <iomanip>
using namespace std;
typedef long long ll;
const double EPS = 1e-9;
typedef vector<int> vint;
typedef pair<int, int> pint;
#define rep(i, n) REP(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for(int i = x; i < n; i++)
template<class T> T RoundOff(T a){ return int(a+.5-(a<0)); }
template<class T, class C> void chmax(T& a, C b){ if(a < b) a = b; }
template<class T, class C> void chmin(T& a, C b){ if(b < a) a = b; }
template<class T, class C> pair<T, C> mp(T a, C b){ return make_pair(a, b); }

double cut(double x)
{	return x - floor(x);	}
int main()
{
	double n;
	while(cin >> n && 0 <= n)
	{
		vector<char> na, de;

		for(int i = n; i; i /= 2)
			na.push_back(i % 2 + '0');

		int lim = 0;
		for(double i = n; lim < 8; i = cut(i) * 2, lim++)
			if(lim)
			{
				de.push_back((1 <= i) + '0');
				if(floor(i) == i) break;
			}

		if(8 < na.size() || 4 < de.size())
			cout << "NA" << endl;
		else
		{
			while(na.size() < 8)
				na.push_back('0');
			while(de.size() < 4)
				de.push_back('0');

			reverse(ALL(na));

			rep(i, 8)
				cout << na[i] << (i == 7 ? "." : "");
			rep(i, 4)
				cout << de[i] << (i == 3 ? "\n" : "");
		}
	}
}

C++: #include<stdio.h>
int main(void)
{
	float a;
	int s,d[13],f,g,h,i,j,z;
	while(1){
		scanf("%f",&a);
		h=0;
		z=a;
		if(z<0){
			break;
		}
		for(i=1;i<=12;i++){
			d[i]=0;
		}
		//printf("%f",a);
		f=a*16;
		i=4096;
		//printf("a == %f\n",a*16);
		s=f;
		j=1;
		while(i!=1){
			i=i/2;
			if(i<=f){
				d[j]=f/i;
				//printf("d[%d] = %d %d %d\n",j,d[j],i,f);
				f=f-i;
			}
			j++;
		}
		if(a>=4096){
			printf("NA\n");
			h=1;
			//printf("1111\n");
		}
		if(d[12]!=1&&d[12]!=0&&h==0){
			printf("NA\n");
			h=1;
		}
		if((a*16)-s>0&&h==0){
			//printf("2222 = %d\n",a*16-s);
			printf("NA\n");
			h=1;
		}
		/*for(i=0;i<12;i++){
			printf("%d\n",d[i]);
		}*/
		if(h==0){
			for(i=1;i<=12;i++){
				printf("%d",d[i]);
				if(i==8){
					printf(".");
				}
			}
			printf("\n");
		}
	}
	return 0;
}

C++: #include <iostream>
#include <cmath>
using namespace std;

int main() {
    while (true) {
        double n;
        cin >> n;
        if (n < 0) {
            break;
        }
        double d_integer, decimal;
        decimal = modf(n, &d_integer);
        string ans = ".";
        bool canTranslate = true;
        int integer = (int) d_integer;
        for (int i = 0; i < 8; i++) {
            if (integer % 2 == 0) {
                ans.insert(0, 1, '0');
            } else {
                ans.insert(0, 1, '1');
            }
            integer /= 2;
        }
        if (integer > 0) {
            canTranslate = false;
        }
        for (int i = 0; i < 4; i++) {
            decimal *= 2;
            if (decimal >= 1) {
                ans += '1';
            } else {
                ans += '0';
            }
            decimal -= (int) decimal;
        }
        if (decimal > 0.0000001) {
            canTranslate = false;
        }
        if (canTranslate) {
            cout << ans << endl;
        } else {
            cout << "NA" << endl;
        }
    }
}

C++: #include <bits/stdc++.h>
using namespace std;

#define for_(i,a,b) for(int i=(a);i<(b);++i)

int main() {
	double d;
		
	while (cin >> d) {
		if (d < 0) break;
		
		int ans = -1;
		
		for_(S,0,(1<<12)-1) {
			double a = 0;
			for_(i,0,12) if (S >> i & 1) a += pow(2.0, 7 - i);
			if (fabs(a - d) < 1e-12) ans = S;
		}
		
		if (ans == -1) cout << "NA";
		else for_(i,0,12) cout << (ans >> i & 1) << (i == 7 ? "." : "");
		cout << endl;
	}
}