Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8642051
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T11:40:48+00:00 2026-06-12T11:40:48+00:00

I am new to python and try to write a script which makes byte

  • 0

I am new to python and try to write a script which makes byte 0x00-0xff output to a file.

This is the code i am currently looking at

import sys

filename="binarywriter.txt"
openmode="wb"
charset="utf8"

file=open(filename, openmode)
for x in range(16,256):
    s="0x%.2x=\\x" %x
    s+=hex(x)[2:]
    d=bytes(s, charset).decode("unicode_escape")
    file.write(d.encode(charset))
    file.write("\r\n".encode(charset))
file.close()
sys.stdin.readline()

The thing is that the python script writes all well until byte 0x7f (which is ascii) after this (0x80) it converts all output in utf8 encoding which has 2 bytes. The thing is to avoid this and only write something like this:

...
0x7f
0x80
0x81
...

so i need something like 8bit encoding but after hour of searching there has not been any result for me

there is also a little problem, where numbers <16 return a single hex value which cannot be decoded, but i might find a solution for this

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T11:40:49+00:00Added an answer on June 12, 2026 at 11:40 am

    You can use Latin-1 (also known as ISO_8859-1) encoding.

    charset="iso-8859-1"
    

    See the screenshot for the proof that every character only needs one byte in the file:
    Screenshot of hexeditor showing file

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This is my python script which creates a test.txt file when executed. when I
I have a new problem with a python script. When I try to run
this is my python script below, I try to use sub() to replace all
I am quite new in python and trying to write a script to login
Very new to python and can't understand why this isn't working. I have a
Brand new to Python (and programming in general), if this is simple and/or answered
I writing a script in python in which I am extracting some information from
I try to write a script that will reset and reinitialize the database for
This is not a new problem for me. From C to PERL to Python
I'm new to programming, and I'm trying to write a Python function to find

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.