what is the meaning of 0x0? say when variable gets assigned to it, example: keccak256(number) = 0x0;
Is 0x0 just zero? thanks
keccak256(number) = 0x0;
Or when not used as address I mean just to denote variable?
solidity remix
add a comment |
Is 0x0 just zero? thanks
keccak256(number) = 0x0;
Or when not used as address I mean just to denote variable?
solidity remix
add a comment |
Is 0x0 just zero? thanks
keccak256(number) = 0x0;
Or when not used as address I mean just to denote variable?
solidity remix
Is 0x0 just zero? thanks
keccak256(number) = 0x0;
Or when not used as address I mean just to denote variable?
solidity remix
solidity remix
asked Mar 11 at 23:08
kpopguykpopguy
374
374
add a comment |
add a comment |
2 Answers
2
active
oldest
votes
The 0x
prefix means hexadecimal and it's a way to tell programs, contracts, APIs that the input should be interpreted as a hexadecimal number (we'll shorten to hex). 0x0
is actually 0
but in hex. Usually we use 0x0
to check whether the address is not set by us and it is set to default value by the solidity which is 0x0.
require(_addressIn != address(0))
E.g. 0x0
in Solidity is short for 0x0000000000000000000000000000000000000000
, and if we use this as some address than it does have value greater than zero. check here.
Keccak256
computes the Ethereum-SHA-3 (Keccak-256) hash (doc) of the arguments passed into the function. So the above line of code is not correct because keccak256(number)
is returning the hash value which you can store in some variable, instead you are trying to treat the output hash value as an variable and assigning the 0x0
to that.
I hope it helps.
1
"0x0 in Solidity is short for 0x0000000000000000000000000000000000000000" I guess technically that's true, just like in decimal, 0 is short for 0000000000 (for any number of 0s). But I think it's misleading to say that, as it makes people think it represents some special value or some specific type. It just means0
.
– smarx
Mar 12 at 1:17
add a comment |
The example given wouldn't actually work because you're trying to assign 0x0
to the keccak
function.
It has the same meaning as bytes32(0)
. So, you can go:
require(bytes32(0) == 0x0);
That would be comparing equivalents. It was possible to compare address
and 0x0
but the trend seems to be toward explicit type casting, so you would go address(0)
with a recent compiler.
This type of expression is often used to validate inputs, in particular, catching important values that were not passed in. This is common:
function doSomething(bytes32 key) ... {
require(key != 0x0);
// carry on
}
Hope it helps.
add a comment |
Your Answer
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "642"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fethereum.stackexchange.com%2fquestions%2f68238%2fwhat-is-the-meaning-of-0x0-say-when-variable-gets-assigned-to-it-example-kecc%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
The 0x
prefix means hexadecimal and it's a way to tell programs, contracts, APIs that the input should be interpreted as a hexadecimal number (we'll shorten to hex). 0x0
is actually 0
but in hex. Usually we use 0x0
to check whether the address is not set by us and it is set to default value by the solidity which is 0x0.
require(_addressIn != address(0))
E.g. 0x0
in Solidity is short for 0x0000000000000000000000000000000000000000
, and if we use this as some address than it does have value greater than zero. check here.
Keccak256
computes the Ethereum-SHA-3 (Keccak-256) hash (doc) of the arguments passed into the function. So the above line of code is not correct because keccak256(number)
is returning the hash value which you can store in some variable, instead you are trying to treat the output hash value as an variable and assigning the 0x0
to that.
I hope it helps.
1
"0x0 in Solidity is short for 0x0000000000000000000000000000000000000000" I guess technically that's true, just like in decimal, 0 is short for 0000000000 (for any number of 0s). But I think it's misleading to say that, as it makes people think it represents some special value or some specific type. It just means0
.
– smarx
Mar 12 at 1:17
add a comment |
The 0x
prefix means hexadecimal and it's a way to tell programs, contracts, APIs that the input should be interpreted as a hexadecimal number (we'll shorten to hex). 0x0
is actually 0
but in hex. Usually we use 0x0
to check whether the address is not set by us and it is set to default value by the solidity which is 0x0.
require(_addressIn != address(0))
E.g. 0x0
in Solidity is short for 0x0000000000000000000000000000000000000000
, and if we use this as some address than it does have value greater than zero. check here.
Keccak256
computes the Ethereum-SHA-3 (Keccak-256) hash (doc) of the arguments passed into the function. So the above line of code is not correct because keccak256(number)
is returning the hash value which you can store in some variable, instead you are trying to treat the output hash value as an variable and assigning the 0x0
to that.
I hope it helps.
1
"0x0 in Solidity is short for 0x0000000000000000000000000000000000000000" I guess technically that's true, just like in decimal, 0 is short for 0000000000 (for any number of 0s). But I think it's misleading to say that, as it makes people think it represents some special value or some specific type. It just means0
.
– smarx
Mar 12 at 1:17
add a comment |
The 0x
prefix means hexadecimal and it's a way to tell programs, contracts, APIs that the input should be interpreted as a hexadecimal number (we'll shorten to hex). 0x0
is actually 0
but in hex. Usually we use 0x0
to check whether the address is not set by us and it is set to default value by the solidity which is 0x0.
require(_addressIn != address(0))
E.g. 0x0
in Solidity is short for 0x0000000000000000000000000000000000000000
, and if we use this as some address than it does have value greater than zero. check here.
Keccak256
computes the Ethereum-SHA-3 (Keccak-256) hash (doc) of the arguments passed into the function. So the above line of code is not correct because keccak256(number)
is returning the hash value which you can store in some variable, instead you are trying to treat the output hash value as an variable and assigning the 0x0
to that.
I hope it helps.
The 0x
prefix means hexadecimal and it's a way to tell programs, contracts, APIs that the input should be interpreted as a hexadecimal number (we'll shorten to hex). 0x0
is actually 0
but in hex. Usually we use 0x0
to check whether the address is not set by us and it is set to default value by the solidity which is 0x0.
require(_addressIn != address(0))
E.g. 0x0
in Solidity is short for 0x0000000000000000000000000000000000000000
, and if we use this as some address than it does have value greater than zero. check here.
Keccak256
computes the Ethereum-SHA-3 (Keccak-256) hash (doc) of the arguments passed into the function. So the above line of code is not correct because keccak256(number)
is returning the hash value which you can store in some variable, instead you are trying to treat the output hash value as an variable and assigning the 0x0
to that.
I hope it helps.
answered Mar 12 at 1:10
Abdullah AzizAbdullah Aziz
1232
1232
1
"0x0 in Solidity is short for 0x0000000000000000000000000000000000000000" I guess technically that's true, just like in decimal, 0 is short for 0000000000 (for any number of 0s). But I think it's misleading to say that, as it makes people think it represents some special value or some specific type. It just means0
.
– smarx
Mar 12 at 1:17
add a comment |
1
"0x0 in Solidity is short for 0x0000000000000000000000000000000000000000" I guess technically that's true, just like in decimal, 0 is short for 0000000000 (for any number of 0s). But I think it's misleading to say that, as it makes people think it represents some special value or some specific type. It just means0
.
– smarx
Mar 12 at 1:17
1
1
"0x0 in Solidity is short for 0x0000000000000000000000000000000000000000" I guess technically that's true, just like in decimal, 0 is short for 0000000000 (for any number of 0s). But I think it's misleading to say that, as it makes people think it represents some special value or some specific type. It just means
0
.– smarx
Mar 12 at 1:17
"0x0 in Solidity is short for 0x0000000000000000000000000000000000000000" I guess technically that's true, just like in decimal, 0 is short for 0000000000 (for any number of 0s). But I think it's misleading to say that, as it makes people think it represents some special value or some specific type. It just means
0
.– smarx
Mar 12 at 1:17
add a comment |
The example given wouldn't actually work because you're trying to assign 0x0
to the keccak
function.
It has the same meaning as bytes32(0)
. So, you can go:
require(bytes32(0) == 0x0);
That would be comparing equivalents. It was possible to compare address
and 0x0
but the trend seems to be toward explicit type casting, so you would go address(0)
with a recent compiler.
This type of expression is often used to validate inputs, in particular, catching important values that were not passed in. This is common:
function doSomething(bytes32 key) ... {
require(key != 0x0);
// carry on
}
Hope it helps.
add a comment |
The example given wouldn't actually work because you're trying to assign 0x0
to the keccak
function.
It has the same meaning as bytes32(0)
. So, you can go:
require(bytes32(0) == 0x0);
That would be comparing equivalents. It was possible to compare address
and 0x0
but the trend seems to be toward explicit type casting, so you would go address(0)
with a recent compiler.
This type of expression is often used to validate inputs, in particular, catching important values that were not passed in. This is common:
function doSomething(bytes32 key) ... {
require(key != 0x0);
// carry on
}
Hope it helps.
add a comment |
The example given wouldn't actually work because you're trying to assign 0x0
to the keccak
function.
It has the same meaning as bytes32(0)
. So, you can go:
require(bytes32(0) == 0x0);
That would be comparing equivalents. It was possible to compare address
and 0x0
but the trend seems to be toward explicit type casting, so you would go address(0)
with a recent compiler.
This type of expression is often used to validate inputs, in particular, catching important values that were not passed in. This is common:
function doSomething(bytes32 key) ... {
require(key != 0x0);
// carry on
}
Hope it helps.
The example given wouldn't actually work because you're trying to assign 0x0
to the keccak
function.
It has the same meaning as bytes32(0)
. So, you can go:
require(bytes32(0) == 0x0);
That would be comparing equivalents. It was possible to compare address
and 0x0
but the trend seems to be toward explicit type casting, so you would go address(0)
with a recent compiler.
This type of expression is often used to validate inputs, in particular, catching important values that were not passed in. This is common:
function doSomething(bytes32 key) ... {
require(key != 0x0);
// carry on
}
Hope it helps.
answered Mar 11 at 23:26
Rob HitchensRob Hitchens
28.9k74483
28.9k74483
add a comment |
add a comment |
Thanks for contributing an answer to Ethereum Stack Exchange!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fethereum.stackexchange.com%2fquestions%2f68238%2fwhat-is-the-meaning-of-0x0-say-when-variable-gets-assigned-to-it-example-kecc%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown