PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Monday, October 17, 2022

[FIXED] How to count int input using python

 October 17, 2022     binary, count, integer, python, string     No comments   

Issue

so i have func that convert bytes to binary and i want to count how many amount binary.

example b'\xd8\xe9\xbdR' binary is 11011000 11101001 10111101 01010010

if it is count how many amount, it will be count 4.

i already tried using split, but it says only can be used in string. so can someone help me to fix it?

here's my code to convert bytes to binary:

def biner(password):
    print(password)
    password[0]
    for my_byte in password:
        if my_byte != None:
            return ' '.join(f'{my_byte:0>8b}' for my_byte in password)

here's the web i tried to count


Solution

So quite simply you can take advantage of your script that already splits your input into your desired separation. So using string.split works just fine here.

def biner(password):
    print(password)
    password[0]
    for my_byte in password:
        if my_byte != None: #probably better to replace with is not None rather than != None
            string_output = ' '.join(f'{my_byte:0>8b}' for my_byte in password)
            return string_output, len(string_output.split(' '))#so here we get your 'count' simply the number of splits defined in string_output


Answered By - Jason Chia
Answer Checked By - Pedro (PHPFixing Volunteer)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing