dec2bin

8 ビュー (過去 30 日間)
Talaria
Talaria 2011 年 8 月 5 日
how do i overcome the limitation of dec2bin of 2^52??
saying i would need to convert numbers greater than 2^52. or is there another possible way to generate all possible binary values of one length. for example: length =3 000, 001, 010, 011, 100, 101, 110, 111.

回答 (4 件)

Arnaud Miege
Arnaud Miege 2011 年 8 月 5 日
It seems to work for me:
>> dec2bin(2^52)
ans =
10000000000000000000000000000000000000000000000000000
>> dec2bin(2^52+1)
ans =
10000000000000000000000000000000000000000000000000001
Arnaud
  4 件のコメント
Talaria
Talaria 2011 年 8 月 5 日
thanks alot, but how to overcome this problem??
Jan
Jan 2011 年 8 月 5 日
@Talaria: Which problem do you want to solve exactly? The limitation of DOUBLEs to 53 bit precision can be solved by using UINT64 variables, which allows numbers until 2^64-1. But there will still be the problem, that the number of permutations exceeds the power of current computers dramatically. In other words: There is no way to solve your problem by brute force. To suggest a smarter solution, it is necessary, that you explain the actual problem with any details at first.

サインインしてコメントする。


Jan
Jan 2011 年 8 月 5 日
A fast method to create permutations with order and repetition is FEX: VChooseKRO-mex:
M = VChooseKRO(uint8([0, 1]), 3)
The UINT8 values need 1/8 of the memory occupied by DOUBLEs.
But if you need all permutations with 52 elements, you need some free RAM: 2^52*52 Bytes = 2.34 TB...

Walter Roberson
Walter Roberson 2011 年 8 月 5 日
With regards to a list of all possible binary values of a given length:
If the length desired is N, there are 2^N such values. You want the dec2bin representation of each, which requires one char per original bit. In MATLAB each char requires 2 bytes, so the required storage would be 2^N * 2 = 2^(N+1) bytes.
According to Wikipedia, the current x86_64 architectures implement only 48 bits of addressing space. If you could find a system that implemented and populated all 48 bits of memory, and there was no overhead associated with the storage of the values, then your limit would be N+1 = 48, which would be N=47 -- the best you could hope to do would be to dec2bin() all of the 47 bit numbers, and that would take you 2^48 bytes which would be 256 TB.
  1 件のコメント
Jan
Jan 2011 年 8 月 5 日
@Talaria: In addition the calculations will need some years.

サインインしてコメントする。


Fangjun Jiang
Fangjun Jiang 2011 年 8 月 5 日
I'd like to put the question this way. See the example first.
>> dec2bin(2^55+[0 1 2 3 4 5 6 7 8 9 10 100 1000])
ans =
10000000000000000000000000000000000000000000000000000000
10000000000000000000000000000000000000000000000000000000
10000000000000000000000000000000000000000000000000000000
10000000000000000000000000000000000000000000000000000000
10000000000000000000000000000000000000000000000000000000
10000000000000000000000000000000000000000000000000001000
10000000000000000000000000000000000000000000000000001000
10000000000000000000000000000000000000000000000000001000
10000000000000000000000000000000000000000000000000001000
10000000000000000000000000000000000000000000000000001000
10000000000000000000000000000000000000000000000000001000
10000000000000000000000000000000000000000000000001100000
10000000000000000000000000000000000000000000001111101000
From the help of uint64:
The values of a UINT64 range from 0 to 18,446,744,073,709,551,615,
(that is, from INTMIN('uint64') to INTMAX('uint64')). Values outside
this range are mapped to INTMIN('uint64') or INTMAX('uint64').
NOTE: The range of values that can be passed to UINT64 from the command
prompt or from an M-file function without loss of precision is 0 to
2^53, inclusive. When reading values from a MAT-file, UINT64 correctly
represents the full range 0 to (2^64)-1.
So, not to ask to generate all the possible binary values of a 55-bits binary number, but, is there a way in MATLAB to generate the binary string of two numbers, say (123+2^55) and (456+2^55) and see the exact difference?
The values are still within 2^64-1 so it should be possible. But how to do it? It sounds like need to write the binary number to a .mat file and then load it back?
  1 件のコメント
Walter Roberson
Walter Roberson 2011 年 8 月 5 日
You need R2011a or later in order to do arithmetic on 64 bit numbers. R2010b extends uint64() to be able to handle hard-coded constants of more than 53 bits, but R2010b does not handle arithmetic on these numbers.
There are ways to handle the computation as uint32 values, but that's usually a nuisance to code directly.
If John d'Errico's "vpi" is still in the file exchange, that could be used.

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeLogical についてさらに検索

タグ

製品

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by