Thread: Addition in less capacity computers

  1. #1
    Registered User
    Join Date
    Apr 2006
    Posts
    3

    Addition in less capacity computers

    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.......

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,661
    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.

  3. #3
    Registered User
    Join Date
    Apr 2006
    Posts
    3
    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???

  4. #4
    Registered User
    Join Date
    Mar 2006
    Posts
    725
    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;}

  5. #5
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,661
    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.

  6. #6
    Registered User OnionKnight's Avatar
    Join Date
    Jan 2005
    Posts
    555
    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
    Code:
    struct bignum* bignum_add (struct bignum* dest, int src)
    {
    
            ...
    
            if (bignum_carriage(dest, src) != 0) {
                bignum_add(dest->next, 1);
            }
    
            ...
    
    }
    But I am also blazed so I might be talking crazy.

  7. #7
    Registered User
    Join Date
    Apr 2006
    Posts
    3
    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,

  8. #8
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,661
    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.

  9. #9
    Registered User
    Join Date
    Mar 2006
    Posts
    725
    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;}

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Numeric addresses for computers
    By great in forum C Programming
    Replies: 4
    Last Post: 08-23-2010, 11:53 AM
  2. Error with a vector
    By Tropicalia in forum C++ Programming
    Replies: 20
    Last Post: 09-28-2006, 07:45 PM
  3. need some help with binary addition.
    By InvariantLoop in forum C++ Programming
    Replies: 21
    Last Post: 01-27-2005, 06:52 AM
  4. Computers as authors
    By hk_mp5kpdw in forum A Brief History of Cprogramming.com
    Replies: 8
    Last Post: 11-22-2004, 08:55 PM
  5. Matrix and vector operations on computers
    By DavidP in forum A Brief History of Cprogramming.com
    Replies: 11
    Last Post: 05-11-2004, 06:36 AM