Inside Bitcoin
Opening the selected file…
Inside Bitcoin
Opening the selected file…
The code behind the network, with room to understand it.
Release published 2026-10-28 · Snapshot fetched 2026-11-01. Latest stable release at fetch time; development branches and Git history are excluded. Only the selected code window and visible folders load here.
502num.SetCompact(0x02123456, &fNegative, &fOverflow);503BOOST_CHECK_EQUAL(num.GetHex(), "0000000000000000000000000000000000000000000000000000000000001234");504BOOST_CHECK_EQUAL(num.GetCompact(), 0x02123400U);505BOOST_CHECK_EQUAL(fNegative, false);506BOOST_CHECK_EQUAL(fOverflow, false);508num.SetCompact(0x03123456, &fNegative, &fOverflow);509BOOST_CHECK_EQUAL(num.GetHex(), "0000000000000000000000000000000000000000000000000000000000123456");510BOOST_CHECK_EQUAL(num.GetCompact(), 0x03123456U);511BOOST_CHECK_EQUAL(fNegative, false);512BOOST_CHECK_EQUAL(fOverflow, false);514num.SetCompact(0x04123456, &fNegative, &fOverflow);515BOOST_CHECK_EQUAL(num.GetHex(), "0000000000000000000000000000000000000000000000000000000012345600");516BOOST_CHECK_EQUAL(num.GetCompact(), 0x04123456U);517BOOST_CHECK_EQUAL(fNegative, false);518BOOST_CHECK_EQUAL(fOverflow, false);520num.SetCompact(0x04923456, &fNegative, &fOverflow);521BOOST_CHECK_EQUAL(num.GetHex(), "0000000000000000000000000000000000000000000000000000000012345600");522BOOST_CHECK_EQUAL(num.GetCompact(true), 0x04923456U);523BOOST_CHECK_EQUAL(fNegative, true);524BOOST_CHECK_EQUAL(fOverflow, false);526num.SetCompact(0x05009234, &fNegative, &fOverflow);527BOOST_CHECK_EQUAL(num.GetHex(), "0000000000000000000000000000000000000000000000000000000092340000");528BOOST_CHECK_EQUAL(num.GetCompact(), 0x05009234U);529BOOST_CHECK_EQUAL(fNegative, false);530BOOST_CHECK_EQUAL(fOverflow, false);532num.SetCompact(0x20123456, &fNegative, &fOverflow);533BOOST_CHECK_EQUAL(num.GetHex(), "1234560000000000000000000000000000000000000000000000000000000000");534BOOST_CHECK_EQUAL(num.GetCompact(), 0x20123456U);535BOOST_CHECK_EQUAL(fNegative, false);536BOOST_CHECK_EQUAL(fOverflow, false);538num.SetCompact(0xff123456, &fNegative, &fOverflow);539BOOST_CHECK_EQUAL(fNegative, false);540BOOST_CHECK_EQUAL(fOverflow, true);541}544BOOST_AUTO_TEST_CASE( getmaxcoverage ) // some more tests just to get 100% coverage545{546// ~R1L give a base_uint<256>547BOOST_CHECK((~~R1L >> 10) == (R1L >> 10));548BOOST_CHECK((~~R1L << 10) == (R1L << 10));549BOOST_CHECK(!(~~R1L < R1L));550BOOST_CHECK(~~R1L <= R1L);551BOOST_CHECK(!(~~R1L > R1L));552BOOST_CHECK(~~R1L >= R1L);553BOOST_CHECK(!(R1L < ~~R1L));554BOOST_CHECK(R1L <= ~~R1L);555BOOST_CHECK(!(R1L > ~~R1L));556BOOST_CHECK(R1L >= ~~R1L);558BOOST_CHECK(~~R1L + R2L == R1L + ~~R2L);559BOOST_CHECK(~~R1L - R2L == R1L - ~~R2L);560BOOST_CHECK(~R1L != R1L); BOOST_CHECK(R1L != ~R1L);561unsigned char TmpArray[32];562CHECKBITWISEOPERATOR(~R1,R2,|)563CHECKBITWISEOPERATOR(~R1,R2,^)564CHECKBITWISEOPERATOR(~R1,R2,&)565CHECKBITWISEOPERATOR(R1,~R2,|)566CHECKBITWISEOPERATOR(R1,~R2,^)567CHECKBITWISEOPERATOR(R1,~R2,&)568}570BOOST_AUTO_TEST_CASE(conversion)571{572for (const arith_uint256& arith : {ZeroL, OneL, R1L, R2L}) {573const auto u256{uint256::FromHex(arith.GetHex()).value()};574BOOST_CHECK_EQUAL(UintToArith256(ArithToUint256(arith)), arith);575BOOST_CHECK_EQUAL(UintToArith256(u256), arith);576BOOST_CHECK_EQUAL(u256, ArithToUint256(arith));577BOOST_CHECK_EQUAL(ArithToUint256(arith).GetHex(), UintToArith256(u256).GetHex());578}580for (uint8_t num : {0, 1, 0xff}) {581BOOST_CHECK_EQUAL(UintToArith256(uint256{num}), arith_uint256{num});582BOOST_CHECK_EQUAL(uint256{num}, ArithToUint256(arith_uint256{num}));583BOOST_CHECK_EQUAL(UintToArith256(uint256{num}), num);584}585}587BOOST_AUTO_TEST_CASE(operator_with_self)588{589arith_uint256 v{2};590v *= v;591BOOST_CHECK_EQUAL(v, arith_uint256{4});592v /= v;593BOOST_CHECK_EQUAL(v, arith_uint256{1});594v += v;595BOOST_CHECK_EQUAL(v, arith_uint256{2});596v -= v;597BOOST_CHECK_EQUAL(v, arith_uint256{0});598}600BOOST_AUTO_TEST_SUITE_END()
Independent explanations by MyBitcoinExplorer. Not affiliated with or endorsed by Bitcoin Core. Guides are educational and do not replace the source or its tests.
Bitcoin Core source © its contributors, distributed under the MIT license. Original notices and bundled third-party licenses are retained in the source tree.