Dear friends,
plz help...........
How to do additions in less capacity computers.?
for ex: In 16 bit compilers, is it possible to do 32 bit additions? if so plz let me know frds.......
Dear friends,
plz help...........
How to do additions in less capacity computers.?
for ex: In 16 bit compilers, is it possible to do 32 bit additions? if so plz let me know frds.......
Yes, it is possible.
Once you understand how carry works (think in base 10, what is 8 + 5, it's 3 and carry 1 into the next column), you can do arithmetic in as many bytes as you like.
If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
If at first you don't succeed, try writing your phone number on the exam paper.
yes my dear Salem,
i am trying to implement as Looka ahead carry generator also.... But those are theoritical concepts.... But In my interview they asked to write a C PROGRAM CODE.....Could u tell me how v can now???
yes my dear Salem,
We're not going to do all your homework for you, you know.
Code:#include <stdio.h> void J(char*a){int f,i=0,c='1';for(;a[i]!='0';++i)if(i==81){ puts(a);return;}for(;c<='9';++c){for(f=0;f<9;++f)if(a[i-i%27+i%9 /3*3+f/3*9+f%3]==c||a[i%9+f*9]==c||a[i-i%9+f]==c)goto e;a[i]=c;J(a);a[i] ='0';e:;}}int main(int c,char**v){int t=0;if(c>1){for(;v[1][ t];++t);if(t==81){J(v[1]);return 0;}}puts("sudoku [0-9]{81}");return 1;}
Post your best attempt at it so far.
If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
If at first you don't succeed, try writing your phone number on the exam paper.
Remember that carriage with addition only let's 1 at most to be added to the next power of 256 (or 'block' of 8-bit bytes) and since there's only the values 1 and 0 that would be returned from a function that returns the carriage it can be treated as boolean and code could be written using a simple if-statement like
But I am also blazed so I might be talking crazy.Code:struct bignum* bignum_add (struct bignum* dest, int src) { ... if (bignum_carriage(dest, src) != 0) { bignum_add(dest->next, 1); } ... }
i got how to add carriage to the number...which is explaind by Onionknight..
But my basic doubt is,if we are using 16 bit compiler,
if we taken two numbers a=65,535,b=65,534
if we add directly it gives some values.which are not correct...
but in order to add properly....
1. i am trying to convert the both numbers in to binary.....
2. Addding bit by bit..
3. if i get carry, it will added to next consequent bits,
4.At finally convert to decimal...
I thought like this v can implement this in C. But problem occured in step 4. that means after adding it may get 17 bits.. how to convert it in to decimal....?
Apart from this in each step, there is sophisticated coding is there..Now i am trying to implement....
Any body plz try to implement each step as a module.....
Thank you for your support,
if ( a < b || a < c ) then overflow occurred, and you need to carry.
Or another way to look at it is
if ( MAX_INT - a < b ) then overflow will occur with a + b
If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
If at first you don't succeed, try writing your phone number on the exam paper.
Converting binary to decimal will probably be one of the harder parts. If you're going to input and output in decimal, you might as well work internally in base 10.
Code:#include <stdio.h> void J(char*a){int f,i=0,c='1';for(;a[i]!='0';++i)if(i==81){ puts(a);return;}for(;c<='9';++c){for(f=0;f<9;++f)if(a[i-i%27+i%9 /3*3+f/3*9+f%3]==c||a[i%9+f*9]==c||a[i-i%9+f]==c)goto e;a[i]=c;J(a);a[i] ='0';e:;}}int main(int c,char**v){int t=0;if(c>1){for(;v[1][ t];++t);if(t==81){J(v[1]);return 0;}}puts("sudoku [0-9]{81}");return 1;}