-2

(0x8877665544332211 >> 8 & 0xffff)

I am trying to convert this operation to hexadecimal, but I have not been successful.

I couldn’t use FParse::HexNumber.

https://docs.unrealengine.com/5.0/en-US/API/Runtime/Core/Misc/FParse/HexNumber64/

Has anyone tried or can help?

#include <iostream>
#include <sstream>
 
int main()
{
    int i = (0x8877665544332211 >> 8 & 0xffff);
 
    std::ostringstream ss;
    ss << std::hex << i;
    std::string result = ss.str();
 
    std::cout << result << std::endl;        // 0x3322
 
    return 0;
}

I wrote this code in standard c++, I couldn't run it on Unreal Engine. I don't understand how FParse::HexNumber works

  • 2
    Please explain what you mean by "convert this operation to hexadecimal". It is also very unclear how whatever that means is related to parsing a string. (Do you mean the opposite of parsing – creating a string with the hexadecimal representation of 13090?) – molbdnilo Sep 04 '22 at 00:59
  • Please clarify your specific problem or provide additional details to highlight exactly what you need. As it's currently written, it's hard to tell exactly what you're asking. – Community Sep 04 '22 at 12:45

1 Answers1

0

Let's start with just 0x8877665544332211 >> 8. One hexadecimal digit represents 4 bits, so 8 bits is two hexadecimal digits. >> means shift right, so this much evaluates to 0x88776655443322.

That gives us: 0x88776655443322 & 0xffff. As above, one hex digit is 4 bits. 0xf means all four bits are set. So, 0xffff is 16 bits, all set. For some bit x, x & 1 = x, so this translates to keeping the 16 least significant bits of the left operand, which is: 0x3322

Jerry Coffin
  • 476,176
  • 80
  • 629
  • 1,111
  • I know how it works. But I couldn't do it in unreal engine. – Kadir OZKAN Sep 03 '22 at 22:01
  • FParse::HexNumber just reads a number, so it'll convert a string containing `3322` into an integer containing 0x3322. If you're looking for something to parse/interpret the entire expression: `0x8877665544332211 >> 8 & 0xffff`, you'll have to look elsewhere. – Jerry Coffin Sep 04 '22 at 02:47