Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[HELP] string into binary
#1
hello everyone,
after trying for hours and not finding a solution, i came here to ask for help.

i have a user input a string, for example : something

I have a binary string :

2007d010000000000000000000000000000000000003c3f786d6c2

i want some of the zeros to be rewritten to include the string that the user has typed:

2007d01000000000000000000000000000something3c3f786d6c2

the string must not get longer cause it will break everything, if the user types a bigger string, more of the zeros has to be rewritten, for example :

2007d0100000000000000000000thisisabigstring3c3f786d6c2
Reply
#2
What have you tried?

Also, out of curiosity, what is this for?
Reply
#3
Do you know how many trailing characters you need to keep? This code assumes it is always 11. It also assumes the replacement characters will always fit in the source string.
s1 = '2007d010000000000000000000000000000000000003c3f786d6c2'
s2 = 'something'
trailing = 11

start = len(s1)-len(s2)-trailing
s3 = ''.join((s1[:start], s2, s1[-trailing:]))
print(s1)
print(s3)
Output:
2007d010000000000000000000000000000000000003c3f786d6c2 2007d01000000000000000000000000000something3c3f786d6c2
This is not "string into binary" but rather making a new string by replacing some characters in a string with characters from another string.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Add one to binary string uwl 2 886 Sep-11-2022, 05:36 PM
Last Post: uwl
  hex file to binary or pcap to binary baran01 1 5,630 Dec-11-2019, 10:19 PM
Last Post: Larz60+
  CSV file from Binary to String mr_byte31 2 13,458 Jul-27-2019, 08:46 PM
Last Post: snippsat
  HELP: String of Zero's and One's to binary byte schwasskin 1 3,832 May-19-2019, 07:31 AM
Last Post: heiner55
  binary search string help kietrichards 1 2,175 Mar-08-2019, 12:43 PM
Last Post: stullis
  converting binary b'0x31303032\n' to "1002" string amygdalas 2 2,598 Nov-07-2018, 03:50 AM
Last Post: amygdalas

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020