mirror of
https://github.com/TheAlgorithms/Python.git
synced 2025-07-05 09:21:13 +08:00
psf/black code formatting (#1277)
This commit is contained in:

committed by
Christian Clauss

parent
07f04a2e55
commit
9eac17a408
@ -2,24 +2,25 @@
|
||||
|
||||
# set decimal value for each hexadecimal digit
|
||||
values = {
|
||||
0:'0',
|
||||
1:'1',
|
||||
2:'2',
|
||||
3:'3',
|
||||
4:'4',
|
||||
5:'5',
|
||||
6:'6',
|
||||
7:'7',
|
||||
8:'8',
|
||||
9:'9',
|
||||
10:'a',
|
||||
11:'b',
|
||||
12:'c',
|
||||
13:'d',
|
||||
14:'e',
|
||||
15:'f'
|
||||
0: "0",
|
||||
1: "1",
|
||||
2: "2",
|
||||
3: "3",
|
||||
4: "4",
|
||||
5: "5",
|
||||
6: "6",
|
||||
7: "7",
|
||||
8: "8",
|
||||
9: "9",
|
||||
10: "a",
|
||||
11: "b",
|
||||
12: "c",
|
||||
13: "d",
|
||||
14: "e",
|
||||
15: "f",
|
||||
}
|
||||
|
||||
|
||||
def decimal_to_hexadecimal(decimal):
|
||||
"""
|
||||
take integer decimal value, return hexadecimal representation as str beginning with 0x
|
||||
@ -56,7 +57,7 @@ def decimal_to_hexadecimal(decimal):
|
||||
True
|
||||
"""
|
||||
assert type(decimal) in (int, float) and decimal == int(decimal)
|
||||
hexadecimal = ''
|
||||
hexadecimal = ""
|
||||
negative = False
|
||||
if decimal < 0:
|
||||
negative = True
|
||||
@ -64,11 +65,13 @@ def decimal_to_hexadecimal(decimal):
|
||||
while decimal > 0:
|
||||
decimal, remainder = divmod(decimal, 16)
|
||||
hexadecimal = values[remainder] + hexadecimal
|
||||
hexadecimal = '0x' + hexadecimal
|
||||
hexadecimal = "0x" + hexadecimal
|
||||
if negative:
|
||||
hexadecimal = '-' + hexadecimal
|
||||
hexadecimal = "-" + hexadecimal
|
||||
return hexadecimal
|
||||
|
||||
if __name__ == '__main__':
|
||||
|
||||
if __name__ == "__main__":
|
||||
import doctest
|
||||
|
||||
doctest.testmod()
|
||||
|
Reference in New Issue
Block a user