Recent

Author Topic: Some fun with bitmanipulations  (Read 2043 times)

Thaddy

  • Hero Member
  • *****
  • Posts: 9152
Re: Some fun with bitmanipulations
« Reply #30 on: October 14, 2019, 02:36:16 pm »
Well, you have helped a lot, thank you!! but I rewrote the architecture on Michael's suggestion...
( the byte /word /integer part I already figured out.. You need word btw, not byte, to handle ordinals on current processors that handle up to 512 (exotics even more) per register and are just not yet implemented, same as current 64)

Anyway, the discussion made me rethink some parts in a fundamental way.
also related to equus asinus.

Tz

  • New Member
  • *
  • Posts: 43
  • Tz with FPC Pen Cil
Re: Some fun with bitmanipulations
« Reply #31 on: October 14, 2019, 04:00:40 pm »
What :o

this are more way seriously fun

Code: Pascal  [Select]
  1. program iso8583;  // https://en.wikipedia.org/wiki/ISO_8583
  2. {$mode objfpc}
  3. {$h+}
  4. uses SysUtils, OrdinalBits;
  5.  
  6. var
  7.   bitmap :QWord;
  8.   i :Integer;
  9.  
  10. begin
  11.  
  12.   bitmap := $2210001102C04804;
  13.   WriteLn(bitmap.ToHexString);
  14.  
  15.   for i:=63 downto 0 do
  16.     WriteLn('bit [',64-i,'] : ', bitmap.TestBit(i));
  17.  
  18. end.
  19.  

and toggle 512 exotic bulbs on or off ...

Awesome   :D :D :D

Thaddy

  • Hero Member
  • *****
  • Posts: 9152
Re: Some fun with bitmanipulations
« Reply #32 on: October 14, 2019, 04:14:18 pm »
Well, testbit won't help you very much but setbit/clearbit and togglebit do... It was designed with electronics in mind.
And yes, you can toggle a lot on or of, you can even MMAP an appropriate value to a hardware control like GPIO.
also related to equus asinus.

Tz

  • New Member
  • *
  • Posts: 43
  • Tz with FPC Pen Cil
Re: Some fun with bitmanipulations
« Reply #33 on: October 14, 2019, 04:43:01 pm »
In ISO8583 TestBit is useful for determine existence of secondary bitmap. 
TestBit(1) in primary bitmap (or 63 in your helper) if true, there must be a secondary bitmap.

Master and Visa are serious and you make programming fun, :D
such ethos are less found today, in my place.

Excellent Thaddy,  and Thank you all for this forum,  so many ideas here.

« Last Edit: October 14, 2019, 04:46:27 pm by Tz »

garlar27

  • Hero Member
  • *****
  • Posts: 618
Re: Some fun with bitmanipulations
« Reply #34 on: October 14, 2019, 05:29:05 pm »
In ISO8583 TestBit is useful for determine existence of secondary bitmap. 
TestBit(1) in primary bitmap (or 63 in your helper) if true, there must be a secondary bitmap.

Master and Visa are serious and you make programming fun, :D
such ethos are less found today, in my place.

Excellent Thaddy,  and Thank you all for this forum,  so many ideas here.


Yeah!!!

I know what you mean Tz, I once had to do it the hard way !!!

And managed everything in strings of '0' and '1' fearing problems with endianness.

jamie

  • Hero Member
  • *****
  • Posts: 2068
Re: Some fun with bitmanipulations
« Reply #35 on: October 14, 2019, 05:41:37 pm »
I haven't looked at the implementation of the bit setting code but I hope it's inline because I hate unused lard in my EXE 's  >:(
Number 1 at blue screen app creations!

Tz

  • New Member
  • *
  • Posts: 43
  • Tz with FPC Pen Cil
Re: Some fun with bitmanipulations
« Reply #36 on: October 15, 2019, 03:20:15 pm »
garlar27  :D

couting finger may be? or check missing tooth?  :D

But this is real word protocol  https://en.wikipedia.org/wiki/Modbus

We can read or wite a coil,  and some enhancement we can read Octal, Nibble, Byte like SubBit(1, 2) = Value 0 - 3

example from digital input device 16 bit register

Name                    Min  Max   Bits/Sign
Unnamed digital input 1 0    15    13/16-16/16
Unnamed digital input 2 0    15    9/16-12/16
Unnamed digital input 3 0    15    5/16-8/16
Unnamed digital input 4 0    15    1/16-4/16


if Thaddy dont mind  :D


Thaddy

  • Hero Member
  • *****
  • Posts: 9152
Re: Some fun with bitmanipulations
« Reply #37 on: October 15, 2019, 04:34:02 pm »
I haven't looked at the implementation of the bit setting code but I hope it's inline because I hate unused lard in my EXE 's  >:(
Of course it is inlined  :D And they are straight C function translations (Oops... :( ) from literature by Dennis Richie... O:-)
(True, but a bit kidding: it is very simple Boolean logic)
« Last Edit: October 15, 2019, 04:36:16 pm by Thaddy »
also related to equus asinus.

Thaddy

  • Hero Member
  • *****
  • Posts: 9152
Re: Some fun with bitmanipulations
« Reply #38 on: October 15, 2019, 04:39:24 pm »
@Tz
Yes, you can use that. I had hardware in mind.
If you know the memory hardware interface start address, you can fpmmap that address and use the helpers.
I  have a new version (on the bug tracker) that verifies if any of the operations actually succeeded.
Will add that here too.
also related to equus asinus.

garlar27

  • Hero Member
  • *****
  • Posts: 618
Re: Some fun with bitmanipulations
« Reply #39 on: October 15, 2019, 05:51:20 pm »
couting finger may be? or check missing tooth?  :D
Yeah !!! Something like that LOL  :D

I don't remember well exactly what I did since many years has passed from that day (I was using Laz 0.9.2 I think). I recall having trouble to convert the the received bitmap string and the BCD string to anything useful, so I did what I could (cast every char to byte then convert it to a binary string or something like that and being careful with the endiannes). Whatever I did back then worked well against the testing server but I wasn't happy....  :-[

Thaddy

  • Hero Member
  • *****
  • Posts: 9152
Re: Some fun with bitmanipulations
« Reply #40 on: October 15, 2019, 05:57:42 pm »
couting finger may be? or check missing tooth?  :D
Yeah !!! Something like that LOL  :D
Well the fingers were never an issue, but the teeth are now perfectly fine: I can even borrow them to you  if you need them %).
also related to equus asinus.