1

I'm porting short python code to c# but I stopped on this line, I don't know what does it mean

array.append( ("%x" % value)[-1] )

anyone? thx

2 Answers 2

2

This: "%x" % value gives you a string containing the value number represented in hexadecimal.

The [-1] gives you the last character of the above.

array.append adds that character to the end of array (which is presumably a list).

You can figure this out by messing around with the Python REPL:

>>> "%x" % 142
'8e'
>>> ("%x" % 142)[-1]
'e'
>>> array = []
>>> array.append(("%x" % 142)[-1])
>>> array
['e']
Sign up to request clarification or add additional context in comments.

Comments

0

That's the same of doing it:

array.append(str(hex(value))[-1])

hex() converts an integer number (of any size) to a lowercase hexadecimal string prefixed with “0x”.

[-1] gives you the last char of a string.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.