How to reduce a random hash to a boolean value

0 votes

In c or a c-like language assuming I have a random_hash what is the cheapest way to reduce it to a boolean value i.e. 0 or 1?

An example random_hash to normalise answers: 0x11bbe8db4e347b4e8c937c1c8370e4b5ed33adb3db69cbdb7a38e1e50b1b82fa

Restrictions: no method/stdlib calls.

Why c-like, I'm actually trying to do it in a language called Solidity, which is modeled after c/javascript, which has a very limited runtime/stdlib.

Oct 26, 2018 in Blockchain by Prerna
• 1,940 points
27 views

1 answer to this question.

0 votes

Take the largest or smallest bit from the hash and use this as the boolean. Actually, taking any bit should be fine, assuming a good hash function. Assuming the hash is an array of unsigned char, you can use the bitwise AND operator &

(hash[0] & 1) > 0
answered Oct 29, 2018 by Christine
• 15,790 points

Related Questions In Blockchain

+1 vote
2 answers

How to return value from a chaincode in Hyperledger Fabric?

Hyperledger Fabric supports only 2 types of ...READ MORE

answered Jun 13, 2018 in Blockchain by Perry
• 17,020 points
917 views
0 votes
1 answer

How to get a value from SQLite to convert it?

Server side: b = BtcConverter(force_decimal=True) p1btc = b.get_latest_price('USD') p1btcr = ...READ MORE

answered Sep 6, 2018 in Blockchain by digger
• 26,550 points
40 views
0 votes
1 answer
0 votes
1 answer

Solidity: How to return id from hash value?

You can do it by storing the hash ...READ MORE

answered Oct 22, 2018 in Blockchain by Omkar
• 67,660 points
192 views
0 votes
1 answer

Truffle tests not running after truffle init

This was a bug. They've fixed it. ...READ MORE

answered Sep 11, 2018 in Blockchain by Christine
• 15,790 points
169 views
0 votes
1 answer
0 votes
1 answer

Solidity geth: Error encountered during contract execution [Bad instruction]

recipes is a dynamic storage array. You need ...READ MORE

answered Oct 15, 2018 in Blockchain by Omkar
• 67,660 points
101 views
0 votes
1 answer
0 votes
1 answer

How to make sure transactions take no fee in a private Ethereum blockchain?

In a private ethereum network you have ...READ MORE

answered Mar 26, 2018 in Blockchain by Christine
• 15,790 points

edited Mar 26, 2018 by Christine 120 views