How to implement big int in C++

前端 未结 13 2110
攒了一身酷
攒了一身酷 2020-11-22 07:48

I\'d like to implement a big int class in C++ as a programming exercise—a class that can handle numbers bigger than a long int. I know that there are several open sou

13条回答
  •  闹比i
    闹比i (楼主)
    2020-11-22 08:13

    My start would be to have an arbitrary sized array of integers, using 31 bits and the 32n'd as overflow.

    The starter op would be ADD, and then, MAKE-NEGATIVE, using 2's complement. After that, subtraction flows trivially, and once you have add/sub, everything else is doable.

    There are probably more sophisticated approaches. But this would be the naive approach from digital logic.

提交回复
热议问题