Welcome to the Pycom forum Forum
    • \[\[global:header.categories\]\]
    • \[\[global:header.recent\]\]
    • \[\[global:header.tags\]\]
    • \[\[global:header.popular\]\]
    • Login

    Explore Pybytes | Official Documentation | Report a Firmware Bug/Issue | GitHub

    bytearray, type and format confusion

    Scheduled Pinned Locked Moved LoPy
    bytearrayformat
    2 Posts 2 Posters 705 Views 2 Watching
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • sorenS Offline
      soren
      last edited by soren

      Hello, I could really use a hint here as to understand the type bytearray which I'm using for sending to a java socket on an rpi.

      In REPL console I typed this:

      data = bytearray()
      print(data)
      **bytearray(b'')**
      data.append(40000)
      print(data)
      **bytearray(b'@')**
      print(data, encoding='utf8')
      **bytearray(b'@')**
      

      What format is this? How come that the int 40000 is shown as '@' ?? It's not hexadecimal and it's not a byte (0-255), but obviously there's something I don't get..

      J 1 Reply Last reply Reply Quote 0
      • J Offline
        jcaron @soren
        last edited by jcaron

        @soren Add ``` alone on the lines before and after your code, or prefix them all with 4 spaces to have them formatted as code.

        40000 % 256 (or 40000 & 255, i.e. keeping the 8 least significant bits) = 64, which is the code point for @.

        1 Reply Last reply Reply Quote 1

        Hello! It looks like you're interested in this conversation, but you don't have an account yet.

        Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.

        With your input, this post could be even better 💗

        Register Login
        • 1 / 1
        • First post
          Last post

        Pycom on Twitter

        Pycom