[Solved] Split bitstream into 40-bit chunks

Discuss the spreadsheet application
Locked
Tailgunner
Posts: 2
Joined: Sat May 20, 2023 9:17 pm

[Solved] Split bitstream into 40-bit chunks

Post by Tailgunner »

I have in a textdocument a long, uninterrupted stream of bits, about 2700.
I would like to import that bitstram in Calc but cut it up in chunks of 40 bits wide.
So each cell should hold 40 bits going from A1 --> An.
I'm very new to Calc, could someone give me some guidance?
Last edited by MrProgrammer on Fri Jun 02, 2023 6:12 am, edited 2 times in total.
Reason: Tagged ✓ [Solved] -- MrProgrammer, forum moderator
OpenOffice 4.1.12 on Windows 10
User avatar
Lupp
Volunteer
Posts: 3548
Joined: Sat May 31, 2014 7:05 pm
Location: München, Germany

Re: Split bitstream

Post by Lupp »

How is the thing you are calling a bit stream represented in the Writer document?
On Windows 10: LibreOffice 24.2 (new numbering) and older versions, PortableOpenOffice 4.1.7 and older, StarOffice 5.2
---
Lupp from München
Tailgunner
Posts: 2
Joined: Sat May 20, 2023 9:17 pm

Re: Split bitstream

Post by Tailgunner »

An uninterrupted sequence of 1 and 0, no spaces or other characters.
OpenOffice 4.1.12 on Windows 10
User avatar
Lupp
Volunteer
Posts: 3548
Joined: Sat May 31, 2014 7:05 pm
Location: München, Germany

Re: Split bitstream

Post by Lupp »

Thus you mean characters, not bits, and the stream is a string?
To split a long string in chunks of equal length you need to calculate the starting positions. Then the MID() function is applicable. It can be completed in different ways, either by a formula for array evaluation or by single-cell-formulas. (Many variants.)
See attached example.
stringChunlksOfEqualLength.ods
(15.24 KiB) Downloaded 44 times
On Windows 10: LibreOffice 24.2 (new numbering) and older versions, PortableOpenOffice 4.1.7 and older, StarOffice 5.2
---
Lupp from München
Alex1
Volunteer
Posts: 726
Joined: Fri Feb 26, 2010 1:00 pm
Location: Netherlands

Re: Split bitstream

Post by Alex1 »

Paste the string to a cell in Calc, then replace (\d{40}) by $1; with regular expressions checked, format as many cells as text as necessary before using Text to columns with ; as separator, and copy the result to one column using the Transpose option.
AOO 4.1.15 & LO 24.2.2 on Windows 10
User avatar
karolus
Volunteer
Posts: 1159
Joined: Sat Jul 02, 2011 9:47 am

Re: Split bitstream

Post by karolus »

Hallo

Code: Select all

sed 's/.\{,40\}/&\n/g' bitstream.txt > bitstream_with_breaks.txt
AOO4, Libreoffice 6.1 on Rasbian OS (on ARM)
Libreoffice 7.4 on Debian 12 (Bookworm) (on RaspberryPI4)
Libreoffice 7.6 flatpak on Debian 12 (Bookworm) (on RaspberryPI4)
User avatar
MrProgrammer
Moderator
Posts: 4904
Joined: Fri Jun 04, 2010 7:57 pm
Location: Wisconsin, USA

Re: Split bitstream

Post by MrProgrammer »

Tailgunner wrote: Sat May 20, 2023 9:21 pm I have in a textdocument a long, uninterrupted stream of bits, about 2700. I would like to import that bitstram in Calc but cut it up in chunks of 40 bits wide.
Open the text document with Writer.
• Edit → Find & Replace → More options → ✓ Regular Expressions → Search for [01]{40} → Replace with &\nReplace All
• Uncheck Regular expressions → Close
• Edit → Select All
• Edit → Copy

Open a Calc document.
• Edit → Paste Special → Unformatted Text → OK
• At the bottom, below Fields, click Standard
• Change the Column Type to Text → OK.

[Tutorial] Text to Columns

If you need any additional assistance attach a Writer document with the long bit string (remove confidential information then use Post Reply, not Quick Reply, and don't attach a picture instead of the document itself). I will not help further unless you attach.

Tailgunner wrote: Sat May 20, 2023 9:21 pm I'm very new to Calc, could someone give me some guidance?
[Tutorial] Ten concepts that every Calc user should know

If this solved your problem please go to your first post use the Edit button and add [Solved] to the start of the Subject field. Select the green checkmark icon at the same time.
Mr. Programmer
AOO 4.1.7 Build 9800, MacOS 13.6.3, iMac Intel.   The locale for any menus or Calc formulas in my posts is English (USA).
Locked