Suppose N is a decimal number, where N represents the last 4 digits of your student
id.
i) Convert N to binary.
ii) Convert N to hexadecimal
Start
Declare integer varaible N
Declare array integer binary[40]
Declare integer varaible index = 0
Read N
while decimal > 0 do
Set binary[index] = decimal mod 2
Set index=index+1
Set decimal = decimal/2
End while
for i = index-1 to 0 Step -1
print binary[i]
end for
Declare integer variable rem
Declare string variable result=""
Declare char array hex[]={'0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F'}
While num>0 do
rem=num mod 16
result=hex[rem]+result
num=num/16
End while
print result
Stop
Comments
Leave a comment