kill(all)$

maxima : understand convert decimal to hexadecimal , version 1.0
peter.vlasschaert@gmail.com, 21/03/2021

load  packages & option
===================

load(lrats)$ ratprint:falss$

convert : decimal→hexadecimal
=========================

print("decimal to hexadecimal code = ")

print("decimal to hexadecimal code = ","?")$

mod : instruction maxima

p1:2545;

p1a:print(" decimal value = ",p1)$

p1b:mod(p1,16);/* remainder */

rem : other computer language : p1 %  16

How to use : While in Maxima: ?
--------------------------------------------

i:0;

while(i<=5) do(
i:i+1,
print(" i = ",i)
)$

remvalue(i);

i;

i:0; /* init :i */

How to use:While and If instruction together in Maxima ?
-----------------------------------------------------------------------------

while(i≤10) do(
  i:i+1, /* counter*/
    
  if i ≤ 3 then
     (i:i+1,
      print(" a) i =",i))
  else
     (i:i+2 ,
      print(" b) i=",i))  
    

                )$

remvalue(i);

rem : test[i] ,fill in the values : 'list s', conditional with respect 'if condition ': test[i]

for i:1 thru 15 do(
  if i > 5 then (test[i]:3*i)
    else (test[i]:5*i)
);

test[3];

s:makelist(test[i],i,1,15);

→ build  function from above code:  'func'

rem :test[i] replaced by test1[i]

func(nn):=block([],
    
for i:1 thru nn 
    do(
  if i > 5 then 
     ( test1[i]:3*i)             
  else
     (test1[i]:5*i )                
      )
)$
    

func(15)$

sb:makelist(test1[i],i,1,15);

check : code ? func 

sc:is(sb=s); /*check: result*/

optimized : code.
------------------------

grind(func)$

Hexadecimal  : system. (Hexa = 16) ,chem (= hexaan 'alkane' ,organic chemistry )
===============================================================

s1:[0,1,2,3,4,5,6,7,8,9,a,b,c,d,e,f];

s1a:makelist(i,i,0,15);

s1[1];

rem : maxima : s1[1] =0 , index  = 1
          python   :  s1[0] =0, index  = 0

s2:[length(s1),length(s1a)];

relation between : {s1,s1a}, both list
------------------------------------------------

s3:maplist("=",s1a,s1);

s3a:reverse(s3);

s3a1:map("=",s1,s1a);

rem : not use  ":" only "=" ,otherwise error  0:0 ? .

s4:makelist(s1[i],i,11,length(s1));
s4a:makelist(s1a[i],i,11,length(s1a));

build function :Deci to Hexa : decihexa (n) , n = integer.
---------------------------------------------------------------------------

--------------------------------------------------------------------------------------------------------------------------------
input   = integer                             {0,1,2,3,4,5,6,7,8,9}                   → 2545
output = hexadecimal code         {0,1,2,3,4,5,6,7,8,9,a,b,c,d,e,f}  → 9f1
---------------------------------------------------------------------------------------------------------------------------------

  =======================================================================

use :' thonny '    python :  >> print(str(hex(2545)))   
                           result : 0x9f1  follows   → 9f1
                           python : >> print(str(hex(255)))  ,control  example 
                            result :0xff      follows   → ff
direct : computation Eulermath  : >pythonmode on ?, see examples 'help files : How to use'
---------------------------------------------------------------------------------------------------------------------------------
rem :  Thonny             →https://thonny.org/
rem :  Eulermath        →http://euler-math-toolbox.de/Programs/Changes.html  ( only windows )
----------------------------------------------------------------------------------------------------------------------------------
========================================================================
python : use tkinter  , #000000  to  #ffffff       → # (red) (green)(blue) →# RGB
red     :   00  to  ff 
green :   00  to  ff   
blue   :    00  to  ff  
-----------------------------------------------------------------------------------------------------------------------------------
rem:
website : https://petervlaschemeng.weebly.com/
-----------------------------------------------------------------------------------------------------------------------------------
new: 19/03/2021:python :Hexadecimal representation of a color (version 1.0) (tkinter,*.txt=>*.py )
download  (Phyton,code)       :colorhexadecimalpython19032021
download  (Phyton,png)         :colorhexadecimalpython19032021outp
=========================================================================

ᐆ  algo : steps

m1:2545;

step 1:
=====

n1:mod(m1,16);

temp:n1;
hd[1]:temp;
temp:0$
m2:floor(m1/16);

step 2:
=====

n2:mod(m2,16);

temp:n2;
hd[2]:temp;
temp:0$
m3:floor(m2/16);

step 3:
=====

n3:mod(m3,16);

temp:n3;
hd[3]:temp;
temp:0$
m4:floor(m3/16);

stop : steps3,   m4 = 0

reverse sequence :

hex1:reverse([n1,n2,n3]);

hex:lratsubst(s3,hex1);

floor(9/16);

ᐇalgo : source code

n:2545;
i:0;

while(n ≠ 0) do(
  temp:mod(n,16),
  i:i+1,  
  hexd[i]:temp,
  temp:0,    
  n:floor(n/16)       

                )$

hex2:reverse(makelist(hexd[j],j,1,i));

hexw:lratsubst(s3,hex2);

ᐇ algo : function

remvalue(i)$ remvalue(j)$
i;

decihexa[mm,sx]:=block([i:0],
    
 while(mm ≠ 0) do(
        
  temp1:mod(mm,16),
  i:i+1,  
  hexd[i]:temp1,
  temp1:0,    
  mm:floor(mm/16)    

                 ),
    ss:reverse(makelist(hexd[j],j,1,i)),
    return(lratsubst(sx,ss))
 
)$

optimized : code.
------------------------

grind(decihexa)$

decihexa[2545,s3];

print("Hexadecimal Value =",simplode(decihexa[2545,s3]))$

rem : color codes , x={R,G,B} :
=======================

print(0," ≤ x ≤ ", simplode(decihexa[255,s3]))$

---------------------------------------------------------------------------------------------------------------------------------------------------------------