Not Yet Answered # Sum numbers in DC and RC

Discussion Starter Mak!zZz Labdabeta 182 Labdabeta 182 ddanbe 2,467 Discussion Starter Mak!zZz Labdabeta 182 Hey, so I wanna ask how I need to create a method who will remove word if in that word is 2 same chars. Example: "Potato" in this word there is a 2 "o" chars so this word will need to be removed. "Forum" in this word there is no ...

0

http://pastebin.com/N1APw9HK

http://pastebin.com/CLAR6jrm

I have only this 2 codes, but they print wrong

0

Those links didn't work (at least not for me) please input them in a code block (just hit the "Code" button on the top of the editor). Also I have a feeling that your description of your problem will be insufficient. Try to clearly describe exactly what you are trying to do.

0

In his first post he did say that it was about the different compliment systems (he misspelled them but he meant Digit and Radix complements) Digit complement in binary is 1s complement, whereas radix complement in binary is 2s complement. Here is -3 stored in a 3-bit number in both:

Digit complement (1s complement):

original is 011 (3), invert all bits to get 100 (-3)

Radix complement (2s complement):

original is 011 (3), most significant bit is negative so 111 is -1, so 101 would be -3 (by subtracting the 2 bit)

The issue is that I can't access his code. If you can could you post it directly here rather than using pastebin?

0

@Labdabeta Thanks for the clarification. As I'm not native English myself, I found the OP used a rather "weird syntax"

0

This is my code, in C, and i have 4 mistakes, can you please check out this code and tell me where are the mistakes. http://imgur.com/M4xQonA

Where it writes "HE" this that is wrong

Thanks

```
#include <stdio.h>
#include <math.h>
#include <string.h>
`int main() {`
int a,i=0,y=0,x=0,sum=0,sum1=0,n,prom;
int b[16],b1[16],zbor[16],new[16];
char aa,st[10];
//printf("Sistem: ");
while(y<=2&&(aa=getchar())!='\n') {
st[y]=aa;
y++;
}
st[y]=0;
//printf("Prv binaren broj: ");
while(i<20&&(a=getchar())!='\n') {
b[i]=a;
i++;
++x;
}
if(st[0]=='D'&&st[1]=='C') {
for(i=0; i<x; i++) {
if(b[i]-48==1) b[i]=0;
if(b[i]-48==0) b[i]=1;
}
//printf("Komplement: ");
//for(i=0;i<x;i++)
//printf("%d",b[i]);
//printf("\n");
for(i=x; i>=0; i--)
if(b[i]) sum+=pow(2,x-i-1);
}
if(st[0]=='R'&&st[1]=='C') {
for(i=x; i>=0; i--)
if(b[i]-48) sum+=pow(2,x-i-1);
}
i=0;
x=0;
//printf("Vtor binaren broj: ");
while(i<20&&(a=getchar())!='\n') {
b1[i]=a;
i++;
++x;
}
if(st[0]=='D'&&st[1]=='C') {
for(i=0; i<x; i++) {
if(b1[i]-48==1) b1[i]=0;
if(b1[i]-48==0) b1[i]=1;
}
//printf("Komplement: ");
//for(i=0;i<x;i++)
//printf("%d",b1[i]);
for(i=x; i>=0; i--)
if(b1[i]) sum1+=pow(2,x-i-1);
}
if(st[0]=='R'&&st[1]=='C') {
for(i=x; i>=0; i--)
if(b1[i]-48) sum1+=pow(2,x-i-1);
}
//printf("\n");
//printf("Prv broj - decimalna vrednost: %d\n",sum);
//printf("Vtor broj - decimalna vrednost: %d\n",sum1);
i=0;
x=0;
n=sum+sum1;
prom=n;
//printf("Zbir: %d\n",n);
while(n!=0) {
a=n%2;
new[i]=a;
if (a==0) zbor[i]=1;
if (a==1) zbor[i]=0;
i++;
n=n/2;
++x;
}
if(st[0]=='D'&&st[1]=='C') {
//printf("Komplement: ");
for(i=x; i>0; i--) {
printf("%d",zbor[i-1]);
}
}
if(st[0]=='R'&&st[1]=='C') {
if (prom==42445) printf("overflow");
else{
for(i=16;i>x;i--)
printf("0");
for(i=x;i>0;i--)
printf("%d",new[i-1]);
}
}
//printf("\n");
sum=0;
for(i=x; i>=0; i--) {
if(new[i-1]) sum+=pow(2,x-i-1);
}
/*if(st[0]=='D'&&st[1]=='C') {
printf("Komplement: ");
for(i=x; i>0; i--) {
printf("%d",zbor[i-1]);
}
}*/
printf("\n");
return 0;
}
```

0

Some descriptive comments (in english) would be very helpful. Your variable names are hard to decode. Rename your variables so that they explain what they are, and use comments to describe your code. Also I would strongly recommend splitting your code into functions, for more legibility.

This article has been dead for over six months. Start a new discussion instead.

Recommended Articles

Help! I want to create a java program that finds the highest even integer among the values entered by the user. Stop asking values when a value less than 1 have been entered. If no even integer is entered, display "No Even Integer"

Here is the sample output that I ...

I am writing a java program that needs to execute shell commands, so I wrote a function that would take the command to execute as a string (ie: "mkdir ~/Folder1") and execute that command with the shell. Here is the function:

```
try
{
Runtime run = Runtime.getRuntime();
Process pr = ...
```