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 6559823
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T13:22:47+00:00 2026-05-25T13:22:47+00:00

I need to efficiently swap the byte order of an array during copying into

  • 0

I need to efficiently swap the byte order of an array during copying into another array.

The source array is of a certain type; char, short or int so the byte swapping required is unambiguous and will be according to that type.

My plan is to do this very simply with a multi-pass byte-wise copy (2 for short, 4 for int, …). However are there any pre-existing “memcpy_swap_16/32/64” functions or libraries? Perhaps in image processing for BGR/RGB image processing.

EDIT

I know how to swap the bytes of individual values, that is not the problem. I want to do this process during a copy that I am going to perform anyway.

For example, if I have an array or little endian 4-byte integers I can do they swap by performing 4 bytewise copies with initial offsets of 0, 1, 2 and 3 with a stride of 4. But there may be a better way, perhaps even reading each 4-byte integer individually and using the byte-swap intrinsics _byteswap_ushort, _byteswap_ulong and _byteswap_uint64 would be faster. But I suspect there must be existing functions that do this type of processing.

EDIT 2

Just found this, which may be a useful basis for SSE, though its true that memory bandwidth probably makes it a waste of time.

Fast vectorized conversion from RGB to BGRA

  • 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-25T13:22:48+00:00Added an answer on May 25, 2026 at 1:22 pm

    Yes there are existing functions like the one linked in the question but its not worth the effort because the size of the data (in this case) means the set up overhead is too high. So instead, it’s better to just read out 2, 4, and 8 bytes at a time and do the swap using intrinsics and write back.

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

Sidebar

Related Questions

In Python I need to efficiently and generically test whether an attribute of a
I need to multiply several 1000s digits long integers as efficiently as possible in
I am having trouble efficiently selecting the information I need to display. Hopefully someone
I need to very efficiently compare two maps in Clojure/Java, and return the difference
I need some way to do the following efficiently in C#: Make program execution
I need order a Queryset by date in desc order, but i need put
I need to efficiently convert a JPG image to a PNG image with index
Problem We need to efficiently display a large (>1000) number of objects in a
Possible Duplicate: Checking if an int is prime more efficiently I need to test
I have string array ( String[] ) and I need to remove the first

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.