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

  • Home
  • SEARCH
  • 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 6164219
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T21:57:25+00:00 2026-05-23T21:57:25+00:00

I am using the Perl Win32::SerialPort module. In this paticular module I sent over

  • 0

I am using the Perl Win32::SerialPort module. In this paticular module I sent over data using the input command. The data that I sent over to a embedded system were scalar data (numbers) using the transmit_char function (if it were C it would be integers, but since its a scripting language I am not sure what the internal format is in perl. My guess is that perl always stores all numbers as 32 bit floating points, which are adjusted by the module when transmitting).

Then after sending the data I receive data using the input command. The data that I recieve is probably in binary form, but perl doesn’t know how to interpret it. I use the unpack function like this

my $binData = $PortObj->input;
my $hexData = unpack("H*",$binData);

Suppose I transmit 0x4294 over the serial cable, which is a command on the embedded system that I am communicating with, I expect a response of 0x5245. Now the problem is with the endianess: when I unpack I get 0x4552, which is wrong. Is there a way to correct that by adjusting the binary data. I also tried h*, which gives me 0x5425, which is also not correct.

Note: the data I receive is sent over Byte at a time and the LSB is sent first

  • 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-05-23T21:57:26+00:00Added an answer on May 23, 2026 at 9:57 pm

    Endianess applies to the ordering of bytes of an integer (primarily). You need to know the size of the integer.

    Example for 32-bit unsigned:

    my $bytes = pack('H*', '1122334455667788');
    my @n = unpack('N*', $bytes);
    # @n = ( 0x11223344, 0x55667788 );
    
    my $bytes = pack('H*', '4433221188776655');
    my @n = unpack('V*', $bytes);
    # @n = ( 0x11223344, 0x55667788 );
    

    See pack. Note the “<” and “>” modifiers to control the endianess where of instructions where the default endianess is not the one you want.

    Note: If you’re reading from the file, you already have bytes. Don’t create bytes using pack 'H*'.

    Note: If you’re reading from the file, don’t forget to binmode the handle.


    Regarding the example the OP added to his post:

    To get 0x5245 from "\x45\x52", use unpack("v", $two_bytes).

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

Sidebar

Related Questions

1.Download source from OpenSSL (openssl-1.0.0d). 2.Build it static using this: > perl Configure VC-WIN32
I have trouble using Perl grep() with a string that may contain chars that
I have a Perl script that I'm attempting to set up using Perl Threads
How do I connect to a MSSQL database using Perl's DBI module in Windows?
Using Perl, Python, or Ruby, can I write a program, probably calling Win32 API,
By default, perl prints \r\n in a win32 environment. How can I override this?
Using Cygwin Perl v5.8.8 and Win32::TieRegistry 0.26. We can get a tied hash object
I'm using Perl and the Image::Magick module to process some JPEGs. I'm using the
I am using XML::Twig to parse my input xml using Perl. I need to
Kinda new to Perl. I am using Perl web API to get the data.

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.