C++: How do I store a 256 bit number, and how do I convert it to hex?

后端 未结 3 1366
轻奢々
轻奢々 2021-01-28 09:10

ints only go to 32 bits, longs to 64bits... so.. what do you do when you are working with a much larger number?

Also, how easy would it be to switch between the binary

3条回答
  •  傲寒
    傲寒 (楼主)
    2021-01-28 09:50

    ints only go to 32 bits, longs to 64bits... so.. what do you do when you are working with a much larger number?

    You use large number libraries.

    Also, how easy would it be to switch between the binary representation and the hex representation?

    I don't understand the question. A number's a number's a number. Are you asking how to print a number in an certain base? You can format output when using streams like so:

    int x = 100;
    
    cout << x << endl; // print decimal value
    cout << oct << x << endl; // print octal value
    cout << hex << x << endl; // print hexadecimal value
    
    100
    0144
    0x64
    

提交回复
热议问题