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

asked Jul 2, 2015 at 20:19

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']
answered Jul 2, 2015 at 20:23
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.

answered Jul 2, 2015 at 20:27

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

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.