To demonstrate my understanding of the Bitcoin mining process, I have been trying to replicate it in MATLAB. However I am not able to get the same proper final hash. In the following example: Block Hashing Example
% code
clear all; close all;header_hex = ['01000000',... '81cd02ab7e569e8bcd9317e2fe99f2de44d49ab2b8851ba4a308000000000000',... 'e320b6c2fffc8d750423db8b1eb942ae710e951ed797f7affc8892b0f1fc122b',... 'c7f5d74d',... 'f2b9441a',... '42a14695'];% Convert Hex to Bin
header_bin = dec2bin(hex2dec(header_hex));% Initiate Java Digester
md = java.security.MessageDigest.getInstance('SHA-256');% First Hash
pass1 = sprintf('%2.2x',typecast(md.digest(int8(header_bin)), 'uint8')');% Convert to Binary
pass1_bin = dec2bin(hex2dec(pass1));% Second Hash
pass2 = sprintf('%2.2x',typecast(md.digest(int8(pass1_bin)), 'uint8')');
Best Answer