Explicit conversion to uint64 results in Conversion failed! error

I want to convert 0xffffffff00000000 to uint64. When I write it in Command Window the value alone, it is already an uint64, but when I write it as uint64(0xffffffff00000000), I simply get "Conversion failed!" error, with no additional text.
How do I fix it?

16 个评论

We cannot reproduce this behaviour (at least in R2026a) :
intmax("uint64")
ans = uint64 18446744073709551615
uint64(0xffffffff00000000)
ans = uint64 18446744069414584320
Which MATLAB version do you use ?
Hello @Torsten!
It is specified in Release section.
We cannot help you in this forum because we cannot reproduce the error in the recent MATLAB release (R2026a).
Contact support:
together with the information about the MATLAB release you are using on your computer.
I am sorry, but up to which Release are responses given in this forum?
Just to make sure, the Matlab version which I am reffering to was identified? Because from your response, I am not sure it was identified.
I am sorry, but up to which Release are responses given in this forum?
People in this forum are MATLAB users, not MATLAB employees. So they usually have access only to the latest releases (2025 - 2026) and thus can only give advice if the error happens for these latest releases. But your case looks like a bug for me - so only the official MATLAB support can help:
Just to make sure, the Matlab version which I am reffering to was identified? Because from your response, I am not sure it was identified.
What do you get if you type
version
ans = '26.1.0.3312084 (R2026a) Update 4'
in the MATLAB command window ? It will tell you the release you are using.
I appreciate your response @Torsten. In few ocassions, a MATLAB employee has helped me in this forum. This was 2 years ago though (2024). I haven't interacted with this forum since then, so maybe they don't do this anymore. But I understand asking in the forum is not the best way to obtain suport from the staff.
The version is 9.8.0.1323502 (R2020a), which I have the impression it wasn't identified it was on R2020a in the first place. Below the question and its answers, alongside with Products and Tags, there is a Release section which tells the Matlab version. That's why I haven't explicitly stated the version (R2020a) in the question itself.
In few ocassions, a MATLAB employee has helped me in this forum. This was 2 years ago though (2024). I haven't interacted with this forum since then, so maybe they don't do this anymore.
There are some employees active in this forum, but there is no guarantee that they read your question and respond to it. Contacting support directly is the way to go :
Steps to Report a Bug
  • Check the public MathWorks Bug Reports database first to see if the issue is already known.
  • Log in to your MathWorks Account.
  • Navigate to My Service Requests and choose Create a New Service Request.
  • Provide a clear description, your MATLAB version, operating system, and a short code example that reproduces the issue. [1, 2, 3]
I could not reproduce on either R2019b or R2021b; unfortunately, I don't have R2020x installed presently.
@Bogdan -Ervin, be sure you've installed any updates for your version that may be available.
NOTA BENE that the "Release" info is so far down the page owing to the excessive white space and organization of the page display that almost nobody ever realizes it's even there; even @Torsten, one of the most veteran didn't catch you had filled it in. Of course, that you were one of the small percentage that did, that so many don't for similar reason on the Questions page cntributes in that one gets used to the fact it probably won't be there, anyway. <grin>. I complained at length about the format clear back in the very beginning of the transistion from usenet that while having the code feature is useful and needed, the information density of the page should be similar, but I didn't win much support. That whole RH column of ad content could be useful including the release info, etc., instead of all white space.
What do you get if you type
which -all uint64
built-in (/MATLAB/toolbox/matlab/datatypes/uint64) built-in (/MATLAB/toolbox/matlab/datatypes/@char/uint64) % char method built-in (/MATLAB/toolbox/matlab/datatypes/@double/uint64) % double method built-in (/MATLAB/toolbox/matlab/datatypes/@int16/uint64) % int16 method built-in (/MATLAB/toolbox/matlab/datatypes/@int32/uint64) % int32 method built-in (/MATLAB/toolbox/matlab/datatypes/@int64/uint64) % int64 method built-in (/MATLAB/toolbox/matlab/datatypes/@int8/uint64) % int8 method built-in (/MATLAB/toolbox/matlab/datatypes/@logical/uint64) % logical method built-in (/MATLAB/toolbox/matlab/datatypes/@single/uint64) % single method built-in (/MATLAB/toolbox/matlab/datatypes/@uint16/uint64) % uint16 method built-in (/MATLAB/toolbox/matlab/datatypes/@uint32/uint64) % uint32 method built-in (/MATLAB/toolbox/matlab/datatypes/@uint64/uint64) % uint64 method built-in (/MATLAB/toolbox/matlab/datatypes/@uint8/uint64) % uint8 method /MATLAB/toolbox/matlab/datatypes/categorical/@categorical/uint64.m % categorical method uint64 is a built-in method % connector.internal.LoggerLevel method uint64 is a built-in method % matlab.lang.OnOffSwitchState method uint64 is a built-in method % simulink.FindSystemTask.Status method uint64 is a built-in method % mf.zero.meta.Language method uint64 is a built-in method % mf.zero.meta.PropertyIterabilityKind method uint64 is a built-in method % mf.zero.zir.NonsequentialAccessKind method uint64 is a built-in method % mf.zero.zir.PropertyIterabilityKind method uint64 is a built-in method % mf.zero.zir.VisibilityKind method uint64 is a built-in method % mf.zero.zir.targetruntime.TargetRuntime method uint64 is a built-in method % mf.zero.zir.targetruntime.MF0Cpp.InitHandWrappersKind method uint64 is a built-in method % mf.zero.zir.targetruntime.MF0Cpp.SetImplementation method uint64 is a built-in method % dig.config.CommandType method uint64 is a built-in method % dig.config.HorizontalAlignment method uint64 is a built-in method % dig.config.ResourceState method uint64 is a built-in method % dig.config.ResourceType method uint64 is a built-in method % dig.model.DisplayState method uint64 is a built-in method % dig.model.EventDataType method uint64 is a built-in method % dig.model.FunctionType method uint64 is a built-in method % dig.model.ValidInBdType method uint64 is a built-in method % dig.model.ViewMode method uint64 is a built-in method % matlab.automation.Verbosity method uint64 is a built-in method % matlab.unittest.internal.fixtures.FolderScope method built-in % gpuArray method /MATLAB/toolbox/parallel/array/distributed/@codistributed/uint64.m % codistributed method /MATLAB/toolbox/parallel/gpu/gpu/@gpuArray/uint64.m % gpuArray method
in the MATLAB command window ?
Does uint64 work for smaller HEX numbers on your computer ?
What is the exact error message you get (I doubt that it's simply "Conversion failed!" - especially the exclamation mark is striking)
Another approach, note the suffix:
0xffffffff00000000u64
ans = uint64 18446744069414584320
Hello @Torsten!
This is what I am given when I type which -all uint64:
built-in (C:\Program Files\Polyspace\R2020a\toolbox\matlab\datatypes\uint64)
C:\Program Files\Polyspace\R2020a\toolbox\matlab\datatypes\categorical\@categorical\uint64.m % categorical method
uint64 is a built-in method % gpuArray method
C:\Program Files\Polyspace\R2020a\toolbox\symbolic\symbolic\@sym\sym.m % sym method
uint64 is a built-in method % slreq.datamodel.AttributeKindEnum method
uint64 is a built-in method % slreq.datamodel.AttributeRegType method
uint64 is a built-in method % slreq.datamodel.AttributeTypeEnum method
uint64 is a built-in method % slreq.datamodel.CustomIdNumbering method
uint64 is a built-in method % slreq.datamodel.MappingDirectionEnum method
uint64 is a built-in method % connector.internal.LoggerLevel method
uint64 is a built-in method % matlab.lang.OnOffSwitchState method
C:\Program Files\Polyspace\R2020a\toolbox\fixedpoint\fixedpoint\+embedded\@fi\uint64.m % embedded.fi method
C:\Program Files\Polyspace\R2020a\toolbox\parallel\parallel\@codistributed\uint64.m % codistributed method
C:\Program Files\Polyspace\R2020a\toolbox\parallel\gpu\@gpuArray\uint64.m % gpuArray method
@Bogdan -Ervin, that looks similar to R2019b; by R2021b all the data types show up as in the list @Torsten showed, but I don't see anything that looks to have aliased it in your system above.
The format presented by @Stephen23 solved my problem. I don't find a button to pin it as the solution though.
Hello @Torsten!
Sorry for the partial response I have given.
As for the other questions, it looks like it works for smaller numbers (for example, doing uint64(0x1) works). It even works for uint64(uint64(0x1)).
Unfourtnately, "Conversion failed!" is all what is shown as the error, as shown in the image below.
Can only Accept Answers, not Comments. @Stephen23 may come back and move it; I'll hold off doing it for the time being anyways...

请先登录,再进行评论。

 采纳的回答

This is Bug Report 3014238, reported fixed in release R2020b. Using the u64 suffix or wrapping the constant in square brackets allows you to work around the bug in release R2020a.
x1 = 0xffffffff00000000u64
x1 = uint64 18446744069414584320
x2 = uint64([0xffffffff00000000])
x2 = uint64 18446744069414584320
x3 = uint64(0xffffffff00000000) % Bug 3014238 in release R2020a
x3 = uint64 18446744069414584320

更多回答(0 个)

产品

版本

R2020a

提问:

about 10 hours 前

回答:

about 2 hours 前

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by