Recent

Author Topic: Store the value of Checkbox  (Read 17942 times)

taazz

  • Hero Member
  • *****
  • Posts: 5368
Re: Store the value of Checkbox
« Reply #30 on: January 06, 2016, 11:23:48 am »
What people are saying here is to use some other base conversion than hex that will allow him to save more value in the same 2 chars eg a base 32 conversion (instead of 16) will allow him to save twice as much info in this 2 chars.
2^32 <> (2 * 2^16)
2^17 = (2 * 2^16)
;-)
erm a base 16 char only support 4 bits not 16 a base 32 should support 6 bits which is not double so yeah I put my foot in it :P
« Last Edit: January 06, 2016, 11:29:20 am by taazz »
Good judgement is the result of experience … Experience is the result of bad judgement.

OS : Windows 7 64 bit
Laz: Lazarus 1.4.4 FPC 2.6.4 i386-win32-win32/win64

Thaddy

  • Hero Member
  • *****
  • Posts: 18924
  • Glad to be alive.
Re: Store the value of Checkbox
« Reply #31 on: January 06, 2016, 11:42:02 am »
It would be possible if there are enough impossible values over a certain range. As suggested but not well explained by the use of groups.
If over  e.g. a range of four checkboxes a certain combination is not possible you can record that combination as an extra boolean constant and xor the results back and forth.
Let's say 1110 is imposible, then that value or its negation can be used to xor in/out an extra value.

That kind of trick can only be employed when there are indeed impossible combinations.
If the number of options from the sixteen checkboxes is exhaustive, all options are possible, then you can't do that. Then you are stuck with the 16 bits in a word.

This kind of tricks were/are quite common in embedded solutions with restricted memory, like if pin 1,2,3 are up pin 4 is always down, so if pin 4 seems up while 1,2,3 are also up it must be pin 17.
These are really very good puzzles to solve....
« Last Edit: January 06, 2016, 11:53:43 am by Thaddy »
Recovered from removal of tumor in tongue following tongue reconstruction with a part from my leg.

x2nie

  • Hero Member
  • *****
  • Posts: 515
  • Impossible=I don't know the way
    • impossible is nothing - www.x2nie.com
Re: Store the value of Checkbox
« Reply #32 on: January 06, 2016, 12:21:57 pm »
Okay, I have a nice progress (but not as sexy as I expected).


By constraint of backward compatible, all of old checkbox values shall be take in account.
now I expand 16 possible representation ('0'..'F' ) into 32 ( '0'..'F', GHJKLMNPQRSTUVWX ).
(I avoid 'I' and 'O' because some serial number avoid confusing of 1&I, 0&O.)


But, it actually only increase 1bit. %)  per character.
So, now, we, maximum can have 5bit (previously = 4bit).
And the maximum is 20bit (previous maximum = 16bit).
Well, it just met @GetMem currently requires : add 4 more checkboxes.


You know, GHJKLMNPQRSTUVWX = 16chars.
Q: How can '0123456789ABCDEF'+'GHJKLMNPQRSTUVWX' = 17 bit?
A: Well, it should be 32bit if I break the constraint of "backward compatible". But I did NOT.


Okay, talk is easy, here is the code:
Code: Pascal  [Select][+][-]
  1. type
  2.  
  3.  
  4.   { TForm1 }
  5.  
  6.  
  7.   TForm1 = class(TForm)
  8.     cb16: TCheckBox;
  9.     cb17: TCheckBox;
  10.     cb18: TCheckBox;
  11.     cb19: TCheckBox;
  12.     cb5: TCheckBox;
  13.     cb4: TCheckBox;
  14.     cb3: TCheckBox;
  15.     cb2: TCheckBox;
  16.     cb1: TCheckBox;
  17.     cb0: TCheckBox;
  18.     cb15: TCheckBox;
  19.     cb14: TCheckBox;
  20.     cb13: TCheckBox;
  21.     cb12: TCheckBox;
  22.     cb11: TCheckBox;
  23.     cb10: TCheckBox;
  24.     cb9: TCheckBox;
  25.     cb8: TCheckBox;
  26.     cb7: TCheckBox;
  27.     cb6: TCheckBox;
  28.     edBinary2: TEdit;
  29.     edBinary3: TEdit;
  30.     edDec2: TEdit;
  31.     edDec3: TEdit;
  32.     edHex1: TEdit;
  33.     edHex2: TEdit;
  34.     edHex3: TEdit;
  35.     Label1: TLabel;
  36.     Label2: TLabel;
  37.     Label3: TLabel;
  38.     lbBinary1: TLabel;
  39.     lbBinary2: TLabel;
  40.     lbDec1: TLabel;
  41.     lbDec2: TLabel;
  42.     lbHex: TLabel;
  43.     edDec1: TEdit;
  44.     lbDec: TLabel;
  45.     lbBinary: TLabel;
  46.     edBinary1: TEdit;
  47.     lbHex1: TLabel;
  48.     lbHex2: TLabel;
  49.     procedure cb15Click(Sender: TObject);
  50.   private
  51.     { Private declarations }
  52.   public
  53.     { Public declarations }
  54.   end;
  55.  
  56.  
  57. var
  58.   Form1: TForm1;
  59.  
  60.  
  61. implementation
  62.  
  63.  
  64. {$R *.lfm}
  65.  
  66.  
  67. var
  68.   BinaryStr: AnsiString = '0000000000000000'+
  69.                           '0000';
  70.   CheckBoxes: CARDINAL;
  71.   CheckBoxs1,CheckBoxs2 : word;
  72.                              
  73. function BinToDec(const AValue : AnsiString): Integer;
  74. var
  75.   I: Integer;
  76. begin
  77.   Result := 0;
  78.   for I := 1 to Length(AValue) do
  79.     Result := Result * 2 + StrToInt(AValue[I]);
  80. end;
  81.  
  82.  
  83. function BinToHex(AValue: AnsiString): AnsiString;
  84. const
  85.   Chrs : array [0..15] of AnsiChar = '0123456789ABCDEF';
  86. var
  87.   Dec: Integer;
  88. begin
  89.   Dec := BinToDec(AValue);
  90.   Result := '';
  91.   while Dec > 0 do
  92.   begin
  93.     Result := Chrs[Dec - Dec shr 4 shl 4] + Result;
  94.     Dec := Dec shr 4;
  95.   end;
  96. end;
  97.  
  98.  
  99. const
  100.   ChrsX : array [0..31] of AnsiChar = '0123456789ABCDEF'+
  101.                                       'GHJKLMNPQRSTUVWX';
  102.  
  103.  
  104. function ByteToSN(b,a: byte): string;
  105. var i : byte;
  106. begin
  107.   assert(b <= $F, 'only support 4bit');
  108.   assert(a <= $F, 'only support 4bit');
  109.   result := ChrsX[ b + (a shl 4) ];
  110. end;
  111.  
  112.  
  113. function WordToSN(b,a: word ): string;
  114. var i, allbits, onegroup, groups : word;
  115. begin
  116.   result := '';
  117.   allbits := 16;
  118.   onegroup := 4;
  119.   groups := allbits div onegroup;
  120.   for i := 0 to groups - 1 do
  121.   begin
  122.     result := ByteToSN(b and $F, a and $1 ) + result;
  123.     b := b shr onegroup;
  124.     a := a shr 1;
  125.   end;
  126. end;
  127.  
  128.  
  129. procedure TForm1.cb15Click(Sender: TObject);
  130. var L,Lhex : integer;
  131.   BC : string; //backward compatible
  132.   AD : string; // addditional
  133. begin
  134.   //L := 16;
  135.   L := length(BinaryStr);
  136.   if (Sender as TCheckBox).Checked then
  137.     BinaryStr[L - (Sender as TCheckBox).Tag] := '1'
  138.   else
  139.     BinaryStr[L - (Sender as TCheckBox).Tag] := '0';
  140.   {
  141.   edBinary1.Text := BinaryStr;
  142.   CheckBoxes := BinToDec(BinaryStr);
  143.   edDec1.Text := IntToStr(CheckBoxes);
  144.   edHex1.Text := '$' + BinToHex(BinaryStr);
  145.   }
  146.  
  147.  
  148.   LHex := 16;
  149.  
  150.  
  151.   // 1. Backward compatible
  152.   BC := copy(BinaryStr, L-LHex +1, L);
  153.   edBinary1.Text := BC;
  154.   CheckBoxs1 := BinToDec(BC);
  155.   edDec1.Text := IntToStr(CheckBoxs1);
  156.   edHex1.Text := '$' + inttohex(CheckBoxs1,4);
  157.  
  158.  
  159.   // 2. Additional, plain
  160.   AD := copy(BinaryStr, 1, L-LHex);
  161.   edBinary2.Text := AD;
  162.   CheckBoxs2 := BinToDec(AD);
  163.   edDec2.Text := IntToStr(CheckBoxs2);
  164.   edHex2.Text := '$' + inttohex(CheckBoxs2,4);
  165.  
  166.  
  167.   // 3. All Altogether
  168.   edBinary3.Text := BinaryStr;
  169.   CheckBoxes := CheckBoxs1 + (CheckBoxs2 shl 16);
  170.   edDec3.Text := IntToStr(CheckBoxes);
  171.   edHex3.Text := '$' + WordToSN(CheckBoxs1,CheckBoxs2);
  172.  
  173.  
  174.  
  175.  
  176. end;
  177.  
  178.  
  179. end.      
When you were logged in, you can see attachments.
Lazarus Github @ UbuntuCinnamon-v22.04.1 + LinuxMintDebianEdition5

x2nie

  • Hero Member
  • *****
  • Posts: 515
  • Impossible=I don't know the way
    • impossible is nothing - www.x2nie.com
Re: Store the value of Checkbox
« Reply #33 on: January 06, 2016, 12:41:58 pm »
just proof of backward compatible (attachments)
When you were logged in, you can see attachments.
Lazarus Github @ UbuntuCinnamon-v22.04.1 + LinuxMintDebianEdition5

x2nie

  • Hero Member
  • *****
  • Posts: 515
  • Impossible=I don't know the way
    • impossible is nothing - www.x2nie.com
Re: Store the value of Checkbox
« Reply #34 on: January 06, 2016, 02:35:23 pm »
What people are saying here is to use some other base conversion than hex that will allow him to save more value in the same 2 chars eg a base 32 conversion (instead of 16) will allow him to save twice as much info in this 2 chars.
2^32 <> (2 * 2^16)
2^17 = (2 * 2^16)
;-)
erm a base 16 char only support 4 bits not 16, a base 32 should support 6 bits which is not double so yeah I put my foot in it :P
6 bits or 5 bits?
I have chars with 32 possible representation '0123456789ABCDEF'+'GHJKLMNPQRSTUVWX'
the maximum I can reach is 5 bit.



Anyway, I was wrong.
No mater backward compatible or not, it still 20bit maximum. I can't reach 32 bit with 32 chars.

attached is correction of visual representation of bit allocation. The logic is identical (same function called)
When you were logged in, you can see attachments.
Lazarus Github @ UbuntuCinnamon-v22.04.1 + LinuxMintDebianEdition5

molly

  • Hero Member
  • *****
  • Posts: 2330
Re: Store the value of Checkbox
« Reply #35 on: January 06, 2016, 02:42:28 pm »
@Thaddy:
Thank you for the clear description on that (i could not have done that myself due being a bit limited in my english vocabulary), but yes that is what taazz meant to say and to which i made a small reference.

Most probably only TS is able to answer if that would be possible for current situation, and probably only for himself (to not reveal too much infomation).

@x2nie:
Thank you for the example, that is what i was thinking about as well (actually i started to play with something similar to show TS but had not yet progressed as far as you did).

@GetMem:
Together with what you wrote later on, only when user upgrade they can use the new serial (including the additional characters), and only from that point forward users can 'unlock' the new features, by issueing a new serial number for them. Old serial numbers will still work, but a old serial number will be unable to unlock the new features.

Actually i believe that is a solution that makes most sense as it is quite normal for end-users to obtain a new copy of their 'license' when they want/require newly introduced features.

It is always possible to decide that some, none or all of the new features are automatically 'unlocked' for users using an old serial number (or perhaps even based on what previous functions where unlocked before, see also my reference to using odd/even).

Unless the storage/usage of the serial number itself is also limited to 16 bits. Since you expressed that using the word itself inside your code is not the issue, i presumed that it is not limited.

In case your decision to not ask questions on the forums anymore is due to the low quality answers that where given by me, then i apologize and would like to ask you to reconsider that decision. I'm still in the process of settling in.

x2nie

  • Hero Member
  • *****
  • Posts: 515
  • Impossible=I don't know the way
    • impossible is nothing - www.x2nie.com
Re: Store the value of Checkbox
« Reply #36 on: January 06, 2016, 02:46:20 pm »
to make it more clear/obvious, attached is difference of bit location of both logic:
« Last Edit: January 06, 2016, 03:04:26 pm by x2nie »
When you were logged in, you can see attachments.
Lazarus Github @ UbuntuCinnamon-v22.04.1 + LinuxMintDebianEdition5

x2nie

  • Hero Member
  • *****
  • Posts: 515
  • Impossible=I don't know the way
    • impossible is nothing - www.x2nie.com
Re: Store the value of Checkbox
« Reply #37 on: January 06, 2016, 03:12:46 pm »
using 64 possible chars I have maximum 24 bits (24 checkboxes).
Code: Pascal  [Select][+][-]
  1. const
  2.   ChrsX : array [0..31] of AnsiChar = '0123456789ABCDEF'+
  3.                                       'GHJKLMNPQRSTUVWX';
  4.  
  5.  
  6.   Charz : array [0..63] of AnsiChar = '0123456789ABCDEF'+
  7.                                       'GHJKLMNPQRSTUVWX'+
  8.                                       'YZabcdefghijkmno'+
  9.                                       'pqrstuvwyz?-^&@#';        


fullcode:
Code: Pascal  [Select][+][-]
  1.  
  2. unit unit1;
  3.  
  4.  
  5. {$MODE Delphi}
  6.  
  7.  
  8. interface
  9.  
  10.  
  11. uses
  12.   LCLIntf, LCLType, LMessages, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  13.   Dialogs, StdCtrls, Menus;
  14.  
  15.  
  16. type
  17.  
  18.  
  19.   { TForm1 }
  20.  
  21.  
  22.   TForm1 = class(TForm)
  23.     cb16: TCheckBox;
  24.     cb17: TCheckBox;
  25.     cb18: TCheckBox;
  26.     cb19: TCheckBox;
  27.     cb20: TCheckBox;
  28.     cb21: TCheckBox;
  29.     cb22: TCheckBox;
  30.     cb23: TCheckBox;
  31.     cbReset: TCheckBox;
  32.     cb5: TCheckBox;
  33.     cb4: TCheckBox;
  34.     cb3: TCheckBox;
  35.     cb2: TCheckBox;
  36.     cb1: TCheckBox;
  37.     cb0: TCheckBox;
  38.     cb15: TCheckBox;
  39.     cb14: TCheckBox;
  40.     cb13: TCheckBox;
  41.     cb12: TCheckBox;
  42.     cb11: TCheckBox;
  43.     cb10: TCheckBox;
  44.     cb9: TCheckBox;
  45.     cb8: TCheckBox;
  46.     cb7: TCheckBox;
  47.     cb6: TCheckBox;
  48.     edBinary2: TEdit;
  49.     edBinary3: TEdit;
  50.     edBinary4: TEdit;
  51.     edDec2: TEdit;
  52.     edDec3: TEdit;
  53.     edDec4: TEdit;
  54.     edHex1: TEdit;
  55.     edHex2: TEdit;
  56.     edHex3: TEdit;
  57.     edHex4: TEdit;
  58.     edHex5: TEdit;
  59.     Label1: TLabel;
  60.     Label2: TLabel;
  61.     Label3: TLabel;
  62.     Label4: TLabel;
  63.     lbBinary1: TLabel;
  64.     lbBinary2: TLabel;
  65.     lbBinary3: TLabel;
  66.     lbDec1: TLabel;
  67.     lbDec2: TLabel;
  68.     lbDec3: TLabel;
  69.     lbHex: TLabel;
  70.     edDec1: TEdit;
  71.     lbDec: TLabel;
  72.     lbBinary: TLabel;
  73.     edBinary1: TEdit;
  74.     lbHex1: TLabel;
  75.     lbHex2: TLabel;
  76.     lbHex3: TLabel;
  77.     procedure cb15Click(Sender: TObject);
  78.     procedure FormCreate(Sender: TObject);
  79.   private
  80.     { Private declarations }
  81.   public
  82.     { Public declarations }
  83.   end;
  84.  
  85.  
  86. var
  87.   Form1: TForm1;
  88.  
  89.  
  90. implementation
  91.  
  92.  
  93. {$R *.lfm}
  94.  
  95.  
  96. var
  97.   BinaryStr: AnsiString = '0000000000000000'+
  98.                           '00000000';
  99.   C32, CheckBoxes: CARDINAL;
  100.   CheckBoxs1,CheckBoxs2 : word;
  101.                              
  102. function BinToDec(const AValue : AnsiString): Integer;
  103. var
  104.   I: Integer;
  105. begin
  106.   Result := 0;
  107.   for I := 1 to Length(AValue) do
  108.     Result := Result * 2 + StrToInt(AValue[I]);
  109. end;
  110.  
  111.  
  112. function BinToHex(AValue: AnsiString): AnsiString;
  113. const
  114.   Chrs : array [0..15] of AnsiChar = '0123456789ABCDEF';
  115. var
  116.   Dec: Integer;
  117. begin
  118.   Dec := BinToDec(AValue);
  119.   Result := '';
  120.   while Dec > 0 do
  121.   begin
  122.     Result := Chrs[Dec - Dec shr 4 shl 4] + Result;
  123.     Dec := Dec shr 4;
  124.   end;
  125. end;
  126.  
  127.  
  128. const
  129.   ChrsX : array [0..31] of AnsiChar = '0123456789ABCDEF'+
  130.                                       'GHJKLMNPQRSTUVWX';
  131.  
  132.  
  133.   Charz : array [0..63] of AnsiChar = '0123456789ABCDEF'+
  134.                                       'GHJKLMNPQRSTUVWX'+
  135.                                       'YZabcdefghijkmno'+
  136.                                       'pqrstuvwyz?-^&@#';
  137.  
  138.  
  139. function ByteToSN(b,a: byte): string;
  140. var i : byte;
  141. begin
  142.   assert(b <= $F, 'only support 4bit');
  143.   assert(a <= $F, 'only support 4bit');
  144.   result := ChrsX[ b + (a shl 4) ];
  145. end;
  146.  
  147.  
  148. function WordToSN(b,a: word ): string;
  149. var i, allbits, onegroup, groups : word;
  150. begin
  151.   result := '';
  152.   allbits := 16;
  153.   onegroup := 4;
  154.   groups := allbits div onegroup;
  155.   for i := 0 to groups - 1 do
  156.   begin
  157.     result := ByteToSN(b and $F, a and $1 ) + result;
  158.     b := b shr onegroup;
  159.     a := a shr 1;
  160.   end;
  161. end;
  162.  
  163.  
  164. function LongWordToSN(c: Cardinal; Chars:array of AnsiChar ): string;
  165. var i,l : byte;
  166. begin
  167.   l := length(Chars);
  168.   result := '';
  169.   while c > 0 do
  170.   begin
  171.     i := c mod l;
  172.     result := Chars[ i ] + result;
  173.     c := c div l;
  174.   end;
  175.   while length(result) < 4 do
  176.         result := '0' + result;
  177. end;
  178.  
  179.  
  180. procedure TForm1.cb15Click(Sender: TObject);
  181. var T,i,L,Lhex, K,M,N : integer;
  182.   BC : string; //backward compatible
  183.   AD : string; // addditional
  184.   J,sk,sm : string;
  185. begin
  186.   //L := 16;
  187.   L := length(BinaryStr);
  188.   T := (Sender as TCheckBox).Tag;
  189.   if (Sender as TCheckBox).Checked then
  190.     BinaryStr[L - T] := '1'
  191.   else
  192.     BinaryStr[L - T] := '0';
  193.  
  194.  
  195.  
  196.  
  197.   {
  198.   edBinary1.Text := BinaryStr;
  199.   CheckBoxes := BinToDec(BinaryStr);
  200.   edDec1.Text := IntToStr(CheckBoxes);
  201.   edHex1.Text := '$' + BinToHex(BinaryStr);
  202.   }
  203.  
  204.  
  205.   LHex := 16;
  206.  
  207.  
  208.   // 1. Backward compatible 16 checkboxes
  209.   BC := copy(BinaryStr, L-LHex +1, L);
  210.   edBinary1.Text := BC;
  211.   CheckBoxs1 := BinToDec(BC);
  212.   edDec1.Text := IntToStr(CheckBoxs1);
  213.   edHex1.Text := '$' + inttohex(CheckBoxs1,4);
  214.  
  215.  
  216.   // 2. Additional, plain 4 checkboxes.
  217.   AD := copy(BinaryStr, 1, L-LHex);
  218.   edBinary2.Text := AD;
  219.   CheckBoxs2 := BinToDec(AD);
  220.   edDec2.Text := IntToStr(CheckBoxs2);
  221.   edHex2.Text := '$' + inttohex(CheckBoxs2,4);
  222.  
  223.  
  224.   // 3. All Altogether, backward compatible
  225.   J := '';
  226.   for i := 1 to Length(AD) do
  227.   begin
  228.     J := J + AD[i] + copy(BC,4 * (Length(AD) - i) +1, 4);
  229.   end;
  230.   edBinary3.Text := J;
  231.   sk := copy(J, L-LHex +1, L);
  232.   K := BinToDec(sK);
  233.   sm := copy(J, 1, L-LHex);
  234.   M := BinToDec(sM);
  235.   //CheckBoxes := CheckBoxs1 + (CheckBoxs2 shl 16);
  236.   N := K + (M shl 16);
  237.   edDec3.Text := IntToStr(N);
  238.  
  239.  
  240.   edHex3.Text := WordToSN(CheckBoxs1,CheckBoxs2);
  241.  
  242.  
  243.   // 4. All Altogether, NON backward compatible
  244.   edBinary4.Text := BinaryStr;
  245.   CheckBoxes := CheckBoxs1 + (CheckBoxs2 shl 16);
  246.   edDec4.Text := IntToStr(CheckBoxes);
  247.   edHex4.Text := LongWordToSN(CheckBoxes, ChrsX);
  248.  
  249.  
  250.   // 5. 64 chars
  251.   edHex5.Text := LongWordToSN(CheckBoxes, Charz);
  252.  
  253.  
  254. end;
  255.  
  256.  
  257. procedure TForm1.FormCreate(Sender: TObject);
  258. begin
  259.   cb15Click(cbREset);
  260. end;
  261.  
  262.  
  263. end.
  264.  

When you were logged in, you can see attachments.
Lazarus Github @ UbuntuCinnamon-v22.04.1 + LinuxMintDebianEdition5

shobits1

  • Sr. Member
  • ****
  • Posts: 271
  • .
Re: Store the value of Checkbox
« Reply #38 on: January 06, 2016, 03:25:30 pm »
But, it actually only increase 1bit. %)  per character.
So, now, we, maximum can have 5bit (previously = 4bit).
And the maximum is 20bit (previous maximum = 16bit).
Well, it just met @GetMem currently requires : add 4 more checkboxes.

correct me if I am wrong, you just increased the required space to store the serial number to 20bits (yes/no).

if I understood GetMem right, the problem not the length of the serial number 4 or 5 chars (it doesn't matter), but the memory required to store the serial number (restricted to 16bits); maybe GetMem can shed light here.

x2nie

  • Hero Member
  • *****
  • Posts: 515
  • Impossible=I don't know the way
    • impossible is nothing - www.x2nie.com
Re: Store the value of Checkbox
« Reply #39 on: January 06, 2016, 03:29:01 pm »
What people are saying here is to use some other base conversion than hex that will allow him to save more value in the same 2 chars eg a base 32 conversion (instead of 16) will allow him to save twice as much info in this 2 chars.
2^32 <> (2 * 2^16)
2^17 = (2 * 2^16)
;-)
erm a base 16 char only support 4 bits not 16, a base 32 should support 6 bits which is not double so yeah I put my foot in it :P
6 bits or 5 bits?
I have chars with 32 possible representation '0123456789ABCDEF'+'GHJKLMNPQRSTUVWX'
the maximum I can reach is 5 bit.
Yes. I am sure 32 base chars can only 5bit.
64 possible chars will 6bit ! And it is maximum we can reach within fixed widht 4 chars, using readable+writable characters.


Meaning, using 128 possible chars is very hard in writing serial number.
Delphi SN & activation key using writable key : #@?^ etc.
When you were logged in, you can see attachments.
Lazarus Github @ UbuntuCinnamon-v22.04.1 + LinuxMintDebianEdition5

x2nie

  • Hero Member
  • *****
  • Posts: 515
  • Impossible=I don't know the way
    • impossible is nothing - www.x2nie.com
Re: Store the value of Checkbox
« Reply #40 on: January 06, 2016, 03:40:01 pm »
But, it actually only increase 1bit. %)  per character.
So, now, we, maximum can have 5bit (previously = 4bit).
And the maximum is 20bit (previous maximum = 16bit).
Well, it just met @GetMem currently requires : add 4 more checkboxes.

correct me if I am wrong, you just increased the required space to store the serial number to 20bits (yes/no).
No. I increase the capacity.
The required space to store the serial number is still 4 chars wide.


old : 0000~FFFF = 16 bits are represented in 4 chars. Capacity = 65,535
new: 0000~XXXX = 20 bits are represented in 4 chars. Capacity = 16,777,215


while:
 0..F = '0123456789ABCDEF' = 16 base chars.
 0..X = '0123456789ABCDEFGHJKLMNPQRSTUVWX' = 32 base chars.
Quote
if I understood GetMem right, the problem not the length of the serial number 4 or 5 chars (it doesn't matter), but the memory required to store the serial number (restricted to 16bits); maybe GetMem can shed light here.
Yes and No.
Yes he said in a picture that he want to store the integer value. If so, we stuck of nonsense of maximum value of WORD is 16 bit.
No, when we talk about serial number, I felt GetMem has given us 4 char space, no mater how they are combined (can be 0..F or 0...Z or '0'..'#' ).


Well, GetMem get serious problem when thinking of Serial Number logic is secret of his company.
I think the real secret is the order of character combination.
Sorry GetMem, I don't want to think bad of you, it just how I felt confusing of your puzzle.
« Last Edit: January 06, 2016, 04:04:45 pm by x2nie »
When you were logged in, you can see attachments.
Lazarus Github @ UbuntuCinnamon-v22.04.1 + LinuxMintDebianEdition5

molly

  • Hero Member
  • *****
  • Posts: 2330
Re: Store the value of Checkbox
« Reply #41 on: January 06, 2016, 03:51:38 pm »
But, it actually only increase 1bit. %)  per character.
So, now, we, maximum can have 5bit (previously = 4bit).
And the maximum is 20bit (previous maximum = 16bit).
Well, it just met @GetMem currently requires : add 4 more checkboxes.

correct me if I am wrong, you just increased the required space to store the serial number to 20bits (yes/no).
No. I increase the capacity.
The required space to store the serial number is still 4 chars wide.
I believe that what shobits1 means, is that OT problem is not the length of the 'given' serial number, but that its internal storage is limited to 16-bits, e.g. in code limited to 16-bit (although Getmem stated that using a word for internal storage of the serial number was not the issue unless i interpreted that incorrectly).

x2nie

  • Hero Member
  • *****
  • Posts: 515
  • Impossible=I don't know the way
    • impossible is nothing - www.x2nie.com
Re: Store the value of Checkbox
« Reply #42 on: January 06, 2016, 04:00:15 pm »
But, it actually only increase 1bit. %)  per character.
So, now, we, maximum can have 5bit (previously = 4bit).
And the maximum is 20bit (previous maximum = 16bit).
Well, it just met @GetMem currently requires : add 4 more checkboxes.

correct me if I am wrong, you just increased the required space to store the serial number to 20bits (yes/no).
No. I increase the capacity.
The required space to store the serial number is still 4 chars wide.
I believe that what shobits1 means, is that OT problem is not the length of the 'given' serial number, but that its internal storage is limited to 16-bits, e.g. in code limited to 16-bit (although Getmem stated that using a word for internal storage of the serial number was not the issue unless i interpreted that incorrectly).


Wow!
As I concerned, when @GetMem implement new logic and still using 16bit (not 20 bit / expand the capacity) he would break the backward compatible. Using ZIP logic will obsolete old customer.
The side effect is yet known: old customer can't use their SN for by using that new logic.

Anyway, he seem using another characters within his SN, to store the additional bits (4 checkboxes).
If so, it's no problem at all.
We are still entertained with his puzzle. ha ha ha
« Last Edit: January 06, 2016, 04:07:49 pm by x2nie »
When you were logged in, you can see attachments.
Lazarus Github @ UbuntuCinnamon-v22.04.1 + LinuxMintDebianEdition5

molly

  • Hero Member
  • *****
  • Posts: 2330
Re: Store the value of Checkbox
« Reply #43 on: January 06, 2016, 04:20:53 pm »
I believe that what shobits1 means, is that OT problem is not the length of the 'given' serial number, but that its internal storage is limited to 16-bits, e.g. in code limited to 16-bit (although Getmem stated that using a word for internal storage of the serial number was not the issue unless i interpreted that incorrectly).

Wow!
As I concerned, when @GetMem implement new logic and still using 16bit (not 20 bit / expand the capacity) he would break the backward compatible. Using ZIP logic will obsolete old customer.
The side effect is yet known: old customer can't use their SN for by using that new logic.
Yes, that conclusion is correct (as i already stated in one of my posts).

tbh, for now the discussion is moot as OT stated that a temp working solution for the problem was implemented where OT was able to store the extra bits somewhere else.

If indeed the character inputted length of the serial number is/was the only limitation, and OT is able to internally use a 20 bit (or bigger) storage for the internal representation for the serial number to 'connect' to the checkboxes, then your examples of using a..z characters for input is imho the better solution to the problem.

In case it's the internal storage of only being able to use 16 bits for the internal representation of the serial number, then i wonder what good it makes to have the sources in front of you -> you can change things to your likings, unless there is another restriction in place (of which we not know about).

The latter could perhaps be a bit of a stretch as OT stated that it was not allowed to do a complete overhaul of the serial number related code, but i do believe that a restriction of not even being allowed to change the internal storage from word to f.e. a qword would be a completely unrealistic and unworkable for the given problem.

shobits1

  • Sr. Member
  • ****
  • Posts: 271
  • .
Re: Store the value of Checkbox
« Reply #44 on: January 06, 2016, 05:05:10 pm »
If indeed the character inputted length of the serial number is/was the only limitation, and OT is able to internally use a 20 bit (or bigger) storage for the internal representation for the serial number to 'connect' to the checkboxes, then your examples of using a..z characters for input is imho the better solution to the problem.

In case it's the internal storage of only being able to use 16 bits for the internal representation of the serial number, then i wonder what good it makes to have the sources in front of you -> you can change things to your likings, unless there is another restriction in place (of which we not know about).
my thought exactly.

but
Hi guys,

I have 16 checkBoxes, each representing a bit(0-unchecked, 1-checked). I can store all the values in 2 bytes:
   Bin(1111 1111 1111 1111) = Dec(65535) = Hex(FFFF).
The fpc "Word" data type is exactly 2 bytes. So far so good.

To make a long story short, for objective reasons(it's beyond my control), I cannot change the data type, yet somehow I must store the value of 1-4 more checboxes. Is this possible somehow? Because nothing comes to my mind right now. I know what I'm asking is not too realistic...it's like sitting 5 people to 3 chairs.

regards,
GetMem
So I think he is restricted to the storage max of 16bits; and I think the temporary solution he mention is to make a second variable(stored elsewhere)  to hold the value of the added 4 checkboxs.

I don't know why he can't change the data type but maybe he works with embedded hardware with firmware that reads the data in specific order in fixed length or something  %).
« Last Edit: January 06, 2016, 05:07:24 pm by shobits1 »

 

TinyPortal © 2005-2018