简体   繁体   中英

How to represent a binary number size greater than 64 bit

I have a binary number which I want to represent in decimal. The number is as follows:

Binary = 1000 11100000 00000000 00000000 00000000 00000000 01101110 10110000 10100101  

Its equivalent hexadecimal representation is as follows :

Hexadecimal = 08 E0 00 00 00 00 6E B0 A5

I am working on Windows 7 and tried using calculator in programmer mode with Bin (Binary) and Qword. However, it has a limit of 64 bit.

Questions:

  • How do I represent this number in decimal?
  • Is there any free tool available to represent this number?
  • Is there any way in C++11/C++ to achieve this?

First determine how large a binary number your platform will support. Let's say it's 64. Divide your binary number into chunks of 64 and do the low-order chunk as normal. Now, the low-order bit of the next chunk represents 2 64 . Convert that chunk like a regular number but multiply it by 2 64 . You could use this technique as many times as you need. The next chunk you would multiply by 2 128 , then the next by 2 192 , etc.

I think you should refer this .

You can use the BigInteger class if you are going for JAVA, here .

Or download this user-defined library for performing calculations over big numbers in C++, here .

The easier solution may be to work from the other side. Generate the binary representations of all powers of 10: 0x1, 0xA, 0x64, 0x3E8, 0x2710, ... until the power of 10 is larger than your number. Then, count how many times each power of 10 occurs (up to 9, of course).

So 0x2F would be 4 * 0xA + 7 * 0xA , ie 47 decimal.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM