## 11121 - Base -2

**Moderator:** Board moderators

### 11121 - Base -2

Hello , please give me a hint . I know that negative binary numbers are the binary number + a number 1 at the beginning , but it is not in this case. I suppose it's an easy problem , because noone didn't ask about it in the forum , but I just can't get it. It's embarassing not to see the easy problems sometimes but I still want to know the solution.

Thanks in advance !

Thanks in advance !

Hello Lame,

Think about Simply Binary number System

good luck!!

Think about Simply Binary number System

Code: Select all

```
16 8 4 2 1
6 = 1 1 0
and negative 2 (-2) base System
16 -8 4 -2 1
6 = 1 1 0 1 0
```

Practice Makes a man perfect

### it seems correct but judges said CE..?

Code: Select all

```
Removed after AC-ed
Thanks to helloneo..
```

Last edited by algoJo on Wed Dec 20, 2006 7:29 am, edited 1 time in total.

Code: Select all

`array subscript is not an integer`

I am using following functions to find the answer.

Can someone help me whats wrong with this code ?

Can someone help me whats wrong with this code ?

Code: Select all

`deleted`

Last edited by pvncad on Thu Mar 08, 2007 3:42 pm, edited 1 time in total.

try to change your data type from

Code: Select all

```
long long n
```

Code: Select all

```
long double n
```

please give some inputs or let me know problem with following code.

Code: Select all

```
#include<stdio.h>
#include <math.h>
void print_binary(long double n)
{
long double n1 = n / -2;
int r;
n = ceill(n1);
if (n == n1) {
r = 0;
}
else {
r = 1;
}
if (n) {
print_binary(n);
}
printf("%d", r);
}
int main()
{
int N, count;
long double n;
count = 1;
scanf("%d", &N);
while (N --) {
scanf("%Lf", &n);
printf("Case #%d: ", count);
print_binary(n);
printf("\n");
count ++;
}
return 0;
}
```

Try this..

Code: Select all

```
if (n < 0.000001 && n > -0.000001) {
print_binary(n);
}
```