From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-25) on ip-172-31-91-241.ec2.internal X-Spam-Level: X-Spam-Status: No, score=0.0 required=3.0 tests=none autolearn=ham autolearn_force=no version=4.0.1 Path: nntp.eternal-september.org!eternal-september.org!feeder.eternal-september.org!.POSTED!not-for-mail From: Lawrence =?iso-8859-13?q?D=FFOliveiro?= Newsgroups: comp.lang.ada Subject: Re: In precision typing we trust Date: Sat, 30 Aug 2025 06:21:47 -0000 (UTC) Organization: A noiseless patient Spider Message-ID: <108u59r$2eq9a$1@dont-email.me> References: <107uv9g$3019a$1@dont-email.me> <107v1ji$303of$1@dont-email.me> <336fbb5f-a279-ea8e-67fd-f62bb00d6a89@irrt.De> <107vfb9$34cpj$1@dont-email.me> <10855lq$gj8l$1@dont-email.me> <1088h1a$19635$1@dont-email.me> <1089p1i$1ig1d$1@dont-email.me> <108aq2p$1qo9o$1@dont-email.me> <108b1r3$1sj3c$1@dont-email.me> <108dh4t$2f5h3$2@dont-email.me> <108dkik$2g20p$1@dont-email.me> <108g1cg$32gqg$2@dont-email.me> <108h6b0$3a75k$2@dont-email.me> <108iiq5$3lihe$3@dont-email.me> <108mhhk$j2jt$1@dont-email.me> <108mis1$j4cj$1@dont-email.me> <108o33p$vok4$5@dont-email.me> <108o6rp$10njb$1@dont-email.me> <108o7cm$10qct$1@dont-email.me> <108o845$10pj9$3@dont-email.me> <108oann$115to$1@dont-email.me> <108occm$11h9j$2@dont-email.me> <108p6qm$184gc$1@dont-email.me> <108r839$1osg9$2@dont-email.me> <108rrqb$1t75f$1@dont-email.me> <108rs57$1t9nv$1@dont-email.me> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Injection-Date: Sat, 30 Aug 2025 06:21:48 +0000 (UTC) Injection-Info: dont-email.me; posting-host="c0b3afac58395fcfe10cd8a8a01c5d34"; logging-data="2582826"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19d/01XAyWUmkQ3nAyCelIb" User-Agent: Pan/0.163 (Kryvyi Rih) Cancel-Lock: sha1:cdSPNx93vWsx+BFi5YhfpipFuOc= Xref: feeder.eternal-september.org comp.lang.ada:66998 List-Id: On Fri, 29 Aug 2025 09:33:27 -0000 (UTC), Kevin Chadwick wrote: > ... I don't believe you understand what I'm talking about as I > believe Python does not have the ability for easily creating e.g. > Unsigned_2, Unsigned_4 or Unsigned_15 and writing just those bits by > assignment to wherever the programmer wants. Something like the following? (Details of the BitVector class omitted, but I can supply them if you’re interested): +*In[2]:*+ [source, ipython3] ---- # constructor: v = BitVector(«width»[, «init»]) # «init» defaults to all zeroes if omitted v1 = BitVector(3, 2) v2 = BitVector(5) v1, v2, int(v1), int(v2) ---- +*Out[2]:*+ ----(BitVector(3, [False, True, False]), BitVector(5, [False, False, False, False, False]), 2, 0)---- +*In[3]:*+ [source, ipython3] ---- # access can be single bits, or use standard Python slice notation v1[0:2], v1[2], v1[1:3], v2[2:5] ---- +*Out[3]:*+ ----(BitVector(2, [False, True]), False, BitVector(2, [True, False]), BitVector(3, [False, False, False]))---- +*In[4]:*+ [source, ipython3] ---- v1[1:3] = [False, True] v2[:] = 13 ---- +*In[5]:*+ [source, ipython3] ---- v1, v2, int(v1), int(v2) ---- +*Out[5]:*+ ----(BitVector(3, [False, False, True]), BitVector(5, [True, False, True, True, False]), 4, 13)---- +*In[6]:*+ [source, ipython3] ---- # “+” does concatenation of BitVectors; note little-endian ordering. v1 + v2, int(v1 + v2) ---- +*Out[6]:*+ ----(BitVector(8, [False, False, True, True, False, True, True, False]), 108)---- +*In[7]:*+ [source, ipython3] ---- # shifts produce results with same number of bits v2, v2 >> 3, v2 << 3, v2[:3] << 3, (v2 + BitVector(3)) << 3 ---- +*Out[7]:*+ ----(BitVector(5, [True, False, True, True, False]), BitVector(5, [True, False, False, False, False]), BitVector(5, [False, False, False, True, False]), BitVector(3, [False, False, False]), BitVector(8, [False, False, False, True, False, True, True, False]))---- +*In[8]:*+ [source, ipython3] ---- v1[1:3] ---- +*Out[8]:*+ ----BitVector(2, [False, True])---- Following all raise errors +*In[9]:*+ [source, ipython3] ---- v2[:1] = v1 ---- +*Out[9]:*+ ---- --------------------------------------------------------------------------- ValueError Traceback (most recent call last) Cell In[9], line 1 ----> 1 v2[:1] = v1 [traceback details omitted] ValueError: value has 3 bits, only allowed 1 for this usage ---- +*In[10]:*+ [source, ipython3] ---- v1[:] = 8 ---- +*Out[10]:*+ ---- --------------------------------------------------------------------------- ValueError Traceback (most recent call last) Cell In[10], line 1 ----> 1 v1[:] = 8 [traceback details omitted] ValueError: value has 4 bits, only allowed 3 for this usage ---- +*In[11]:*+ [source, ipython3] ---- v2[0] = 2 ---- +*Out[11]:*+ ---- --------------------------------------------------------------------------- ValueError Traceback (most recent call last) Cell In[11], line 1 ----> 1 v2[0] = 2 [traceback details omitted] ValueError: value has 2 bits, only allowed 1 for this usage ---- +*In[12]:*+ [source, ipython3] ---- v1[:] = v2[:] ---- +*Out[12]:*+ ---- --------------------------------------------------------------------------- ValueError Traceback (most recent call last) Cell In[12], line 1 ----> 1 v1[:] = v2[:] [traceback details omitted] ValueError: value has 5 bits, only allowed 3 for this usage ----