So that means our upper boundary i.e. target can be defined as

`var target = new BigInteger(1) << 256 - 24`

And when we create the hash of new block then we compare it with target. i.e.

```var hashInt = new BigInteger(hashBytes)
if (hashInt.CompareTo(target) == -1) {
//It is a valid hash
}```

For this question let’s assume values would be

target:

`6901746346790563787434755862277025452451108972170386555162524223799296`

hashInt:

`-50765282004551092829298895592266344483300201926640276338429566691241878315064`

and their hex values would be (which are calculated by calling .ToString("x") on these variables)

target:

`10000000000000000000000000000000000000000000000000000000000`

hashInt:

`8fc3de5d792f2e6b3118697d1e5baa405400e9f8f09625d7eed1481ee0b09fc8`

Now when we do hashInt.CompareTo(target) == -1 then it returns true. I completely understand why it’s that, but what I want to do is to compare their hex values and if somehow we would be able to do that then on compare it will return false which is what I want.

Aug 27, 2018 480 views

## 1 answer to this question.

You can compare two sequences of equal length with Zip:

```static int CompareSequenceTo<T>(this IEnumerable<T> a, IEnumerable<T> b) where T : IComparable<T> {
return a
.Zip(b, (x, y) => x.CompareTo(y))
.FirstOrDefault(r => r != 0);
}```

Applied to a difficulty a and hash b, it correctly reports that a is less than b:

```byte[] a = {0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
byte[] b = {0x8f, 0xc3, 0xde, 0x5d, 0x79, 0x2f, 0x2e, 0x6b, 0x31, 0x18, 0x69, 0x7d, 0x1e, 0x5b, 0xaa, 0x40, 0x54, 0x00, 0xe9, 0xf8, 0xf0, 0x96, 0x25, 0xd7, 0xee, 0xd1, 0x48, 0x1e, 0xe0, 0xb0, 0x9f, 0xc8};

Console.WriteLine(a.CompareSequenceTo(b));  // some value less than zero```
• 26,740 points

## Related Questions In Blockchain

You could use a recent feature known ...READ MORE

+1 vote

## Security Properties of Hash Functions

The difference is indeed subtle. I understood ...READ MORE

+1 vote

## When is the Transmission of new blocks happen between nodes of the network?

When a block is mined, it is ...READ MORE

+1 vote

+1 vote

## Protocols used in a distributed/dlt system for the nodes to establish communication

yes all are over TCP/IP connections secured ...READ MORE

+1 vote

## How to perform a simple 1-to-1 Bitcoin Transaction with Bitcore?

What is the argument utxos int the ...READ MORE

## Truffle tests not running after truffle init

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

## Hyperledger Sawtooth vs Quorum in concurrency and speed Ask

Summary: Both should provide similar reliability of ...READ MORE

+1 vote