Truncating to a given bit length
조회 수: 14 (최근 30일)
이전 댓글 표시
I have a gui which gives a result as follows. Result=a253ff09c5a8678e1fd1962b2c329245e139e45f9cc6ced4e5d7ad42c4108fc0. Is there a way to truncate the above result to a given bit length? (Say bit lengths of 19,13,10 etc.)
Please help me with the above question.
Thanks a lot in advance.
댓글 수: 1
Walter Roberson
2015년 12월 30일
This question seems likely to be related to http://uk.mathworks.com/matlabcentral/answers/262105-using-hash-functions-editing-contents-of-uitable and might even be the same question.
채택된 답변
Walter Roberson
2015년 12월 30일
Assuming Result is a string and assuming that the values represent hex,
NeededBitLength = 19; %for example
bitvec = reshape(dec2bin(sscanf(Result,'%1x'),4).',1,[]);
bitvec = bitvec(end-NeededBitLength+1 : end);
truncatedResult = bin2dec(bitvec);
Caution: if you need more than 53 bits this version will not work.
댓글 수: 4
Walter Roberson
2016년 1월 6일
I am certain that SHA-256 does not expect you to work with word lengths of more than 64 bits. Typical implementations work with arrays of 32 bit words.
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Debugging and Analysis에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!