# How are enums converted to uint?

When using `web3`, calling a function that returns an `enum` type converts it to a `uint`. Initially I assumed that `enums` are converted incrementally: `0,1,2,3...`. However what I received was a hexadecimal. How is it converted, and how do you parse it?

For example:

``````contract Foo {
enum Letter {A, B, C}
function say(uint index) returns (Letter) {
if(index == 0) return Letter.A;
if(index == 1) return Letter.B;
if(index == 2) return Letter.C;
throw;
}
}
``````

If you call `Foo.say.call(1)` you get a hex number (`0x3ad324...`). How would I check if it was `Letter.A` or 'Letter.B` that was returned?

Enum values are numbered in the order they're defined, starting at 0. So, `Letter.A` will be 0, `Letter.B` will be 1, and so forth. There's currently no means to cast an enum value to its name; that information isn't retained at runtime.

• I thought this was the case as well! However what I got from `web3` were hashes, not incremental numbers. May 20, 2016 at 15:11
• @latrasis You haven't included any web3 code in your question, so I can only speculate. Perhaps you're sending a transaction instead of making a local call, in which case you're getting back a transaction hash? May 20, 2016 at 15:24
• I just realized I forgot to add constant, you were right, thank you! May 21, 2016 at 20:34
• for those reading this in 2020's, note that the statement ""there's currently no means to cast an enum value to its name" hasn't been true since at least November 2016. See @BinGoGoBin's answer below. Dec 22, 2021 at 3:45

nums are one way to create a user-defined type in Solidity. They are explicitly convertible to and from all integer types but implicit conversion is not allowed. The explicit conversions check the value ranges at runtime and a failure causes an exception. Enums needs at least one member.

Enum values are numbered in the order they're defined, starting at 0. If you want get value of enum, calling `uint(enum_variable)`.

``````pragma solidity ^0.4.4;

contract SimpleEnum {

function SimpleEnum(){
}

function setValues(uint _value) {