简体   繁体   中英

Convert a large number, from Base 256 to Base 10

I need to convert very large numbers from Base 256 (bytes) to Base 10 (decimal) in C# or Delphi. The actual goal is to represent contents of any given file as a very large decimal number and save it in a txt file, for example. We all know how to convert from one base to another, but the real challenge here is the size of the number. Any help would be appreciated.

I strongly suspect that if you're using .NET 4 or higher, you'll be able to use the BigInteger(byte[]) constructor - and then convert the result to a decimal string if you want to (or just use it as a number ). You may need to reverse the bytes in the input array depending on the endianness of your input.

As of your update, this is pretty straightforward.

It sounds like you're trying to read the binary file in terms of chars, using some getc() function (the exact name escapes me). Every char is represented by one byte, hence 256 options. This gives chars a certain level of permeability with 8 bit ints. You should be able to read in a character and cast it to an integer, which will give you the decimal representation of the character's 8 bits.

Also chars aren't base 256, they're just 8 bit binary numbers.

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