117k views
4 votes
Write a general-purpose program with loop and indexed addressing that adds 12h to 0th, 3rd , 7th , 11th ,15th ,19th , … elements of a DWORD array. For example, in array:

1 Answer

0 votes

Answer:

def ishex(mylist):

hnum = 0x12

for index, item in enumerate(mylist):

if int(str(item), 16):

if index == 0:

print(hex(item + hnum))

elif item in mylist[3::4]:

print(hex(item + hnum))

else:

print(hex(item))

Dword = [0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f]

ishex(Dword)

Step-by-step explanation:

The python source code defines a function called "ishex" which takes a list as its parameter, loops through its index and value, checks if it is a hexadecimal number and adds 0x12 to every fourth index value of the list "Dword".

User Graham Smith
by
4.5k points