how i can convert binary 128 bit to decimal??

조회 수: 28 (최근 30일)
nail
nail 2014년 5월 30일
댓글: Radwa 2015년 1월 14일
i work in data encryption, but i don't know how to convert a 128 binary to decimal. i try bin2dec and its not work and the error massage tell me : "Binary string must be 52 bits or less". please help
a=dec2bin(7,128)
b=bin2dec(a)
Error using bin2dec (line 36)
Binary string must be 52 bits or less.
  댓글 수: 1
nail
nail 2014년 6월 1일
편집: nail 2014년 6월 1일
Thank you all
nothing works
but i change my code variables to make the output range (8-52) if i know how to make it bigger (64,128,.....) i will change just the conditions :)
you are help me so much
but i want to get 128 bits of it as binary of string data example
1= 00110001
2= 00110010
a= 01100001
b= 01100010
A= 01000001

댓글을 달려면 로그인하십시오.

채택된 답변

James Tursa
James Tursa 2014년 5월 31일
편집: James Tursa 2014년 5월 31일
Double precision numbers only have a 52-bit mantissa (+1 hidden leading bit), hence the error. A uint64 has 64 bits, and that is the max you can have for numeric types. To deal with this many bits in a number you will need to use something else. E.g either the Symbolic Toolbox, or use the Variable Precision Integer FEX submission by John D'Errico:
  댓글 수: 2
nail
nail 2014년 5월 31일
편집: nail 2014년 5월 31일
Thank you James Tursa but i want to get something help me in my code. are you want to say its impossible ?? thank you again
James Tursa
James Tursa 2014년 5월 31일
I don't understand your comment. If you want a single variable to hold the decimal value of a 128-bit binary string, you can't do it with numeric types in MATLAB because there aren't enough bits available. You could use one of the methods I proposed, or perhaps break up your problem into 64-bit chunks and use uint64 types.

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Hind Thanoon
Hind Thanoon 2014년 5월 31일
Hello nail.. try the following code:
a=dec2bin(7,128); b=bin2dec(a(1:24))*2^104+bin2dec(a(25:76))*2^52+bin2dec(a(77:128))*2^0;
this will help you to solve your problem you will convert each 52 bit separately and then accumulate the result like the following example: a=1001=9, if I need to convert each 2bit then I will say bin2dec(10)*2^2+bin2dec(01)*2^0 {bin2dec(a(1:2))*2^2+bin2dec(a(3:4))*2^0} the result will be: 2*2^2+1*2^0=9
  댓글 수: 2
James Tursa
James Tursa 2014년 5월 31일
There are not enough bits in a double variable to hold the exact value of a 128-bit binary string, so your method of breaking things up and accumulating the result will not work in general.
Radwa
Radwa 2015년 1월 14일
I work in encryption also, how u solve ur problem?

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Data Type Conversion에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by