Bit-based functions in 8.3.10


If you wish to leave comments or ask questions, please log on or sign up.

The 1C:Enterprise developers forum

#1
People who like this:0Yes/0No
Interested
Rating: 27
Joined: Oct 27, 2011
Company: Abaco Soluciones S.A.

1C implemented functions to mask bits and work with binary data. I have tried the new possibilities, but found them quite uncomfortable. I have to write like 20 lines of code for quite a simple bit operations.

How would you implement in 1C:Enterprise script something like:

Code
Result:= (A shr 24) or ((A shr 8) and $FF00) or ((A shl 8) and $FF0000) or (A shl 24)

It is not made up. It is a part of sha-1 calculation.

 
#2
People who like this:0Yes/0No
Administrator
Rating: 6
Joined: Nov 3, 2011
Company: 1C Company

Alexey,

yes, the implementation of this algorithm in 1C:Enterprise version 8.3.10 is tricky. Having bit shift functions in 1C:Enterprise script would help and reduce your 20 lines to a single one.

I'm sending the request for bit shift functions to the platform development team.

 
#3
People who like this:0Yes/0No
Interested
Rating: 27
Joined: Oct 27, 2011
Company: Abaco Soluciones S.A.

It is not just bit shift functions. Try to implement smth like:

Code
Result:= A or ((A xor D) and $FF00) or A and $FF0000) or (A xor C)

Edited: Alexey Gerasimov - May 08, 2017 06:13 PM
 
#4
People who like this:1Yes/0No
Just came
Rating: 1
Joined: Apr 8, 2013
Company: 1C Company

Hi, Alexey,

You can calculate popular cash functions (CRC32, MD5, SHA1, and SHA256) out-of-box.
To find out more look at HashFunction in the syntax assistant.

 
#5
People who like this:0Yes/0No
Just came
Rating: 1
Joined: Apr 8, 2013
Company: 1C Company

Julia,

I would like also get native bitwise operations support in the platform to calculate HMAC and other crypto algorithms.

 
#6
People who like this:0Yes/0No
Administrator
Rating: 6
Joined: Nov 3, 2011
Company: 1C Company

I added logical bitwise operations to the feature request. We definitely need the entire package of bitwise functions.

 
#7
People who like this:0Yes/0No
Interested
Rating: 27
Joined: Oct 27, 2011
Company: Abaco Soluciones S.A.

Anton, Thank you for pointing out HashFunction.

Actually 1c hash functions implementation is quite confusing, because there are HashAlgorithm and it is a part of CryptoManager that does not have good documentation.

And HashFunction is part of DataHashing. It is quite easy to be confused which one is part of which package.

Yulya, I understand why 1c still not implemented bitshift functions. There is no Word, int, dword data types. But still there are quite a lot of examples where I need to read some files with bit masking. Current implementation makes this process quite painful.. look at this code:

Code
Function Mask(Byte, ByteMask)
   MaskNumber = NumberFromBinaryString(ByteMask);
   InputBuffer = BufferFromByte(Byte);
   MaskBuffer = BufferFromByte(MaskNumber);
   InputBuffer.WriteBitwiseAnd(0,MaskBuffer,1);
   Return InputBuffer[0];
EndFunction
   

Function BufferFromByte(Byte)
   Buffer = New BinaryDataBuffer(1);
   Buffer[0] = Byte;
   Return Buffer;
EndFunction

      CurByte = DataReader.ReadByte();
      CurNumber = CurNumber * 128 + Mask(CurByte, "0b01111111");
      If 0=Mask(CurByte, "0b10000000") Then


This is not easy to read code...

 
#8
People who like this:0Yes/0No
Administrator
Rating: 6
Joined: Nov 3, 2011
Company: 1C Company

Alexey, I understand your pain. That is why I added a feature request and I will keep you informed on its progress.

 
#9
People who like this:0Yes/0No
Administrator
Rating: 6
Joined: Nov 3, 2011
Company: 1C Company

Good news, everyone! Bitwise operations will make their way to 1C:Enterprise 8.3.11.

 
#10
People who like this:0Yes/0No
Interested
Rating: 27
Joined: Oct 27, 2011
Company: Abaco Soluciones S.A.

Great news! Thanks for keeping us up to date.

 
Subscribe