Big endian, little endian, and converting to another datatype.

Hi all,
I'm working on a sound visualization program. I'm putting the sound into byte arrays, and I then need to convert those bytes into ints to draw onto the screen. This is easy if the soulds are 8-bit, because you don't have the endian issue. How do I take a byte[] and pull ints from it that represent the waveform that the bytes were pulled from? Is it something like this (where soundBytes is the byte[] pulled from a sound file):
int sampleFirstPart = (int)soundBytes[0];
int sampleSecondPart = (int)soundBytes[1];
int putTogether = sampleFirstPart + sampleSecondPart * 128;
That's just a wild guess, and I'm not really sure what order these things should go in. How do you do it if it's big-endian? What about if it's little-endian? Is there a preference of one over the other? Does the fact that I'm working with wav files make a difference.
I'm just full of questions, but any ammount of help you can give is very very much appreciated.
thanks,
Matt

int value = soundBytes[x] + (soundBytes[x+1] << 8); // LE
or
int value = (soundBytes[x] << 8) + soundBytes[x+1]; // BE
I think the LE and BE labels are right, but the calculation part is correct for one or the other.
However, you need to know the format of the file to know if it's one or the other. You can't really tell from the bytes whether it's one or the other. There should, presumably, be some way to know from the audio format header. Either there'd be a flag to incidate which, or it would be assumed one way or the other because it's of format X. I think that wav files would be LE, but don't quote me on that.

Similar Messages

  • Any need for conversation from big endian and little endian?

    Hi,
    I am planning to migrate an Oracle 9i Database on AIX 5.3 to Oracle 11g R2 Windows 2008, and have planned to use transportable tablespace. But prior to that task is the conversation required from big endian and little endian using RMAN?
    Appreciate any suggestions, comments and hints
    Thanks

    Hi,
    Check V$TRANSPORTABLE_PLATFORM, it shows the ending for each supported platform. Given the results on my 11g, I suspect that you'll have to convert the tablespaces...
    SYSTEM@oracle11 SQL>select *
      2   from V$TRANSPORTABLE_PLATFORM
      3  ;
    PLATFORM_ID PLATFORM_NAME                                                                                         ENDIAN_FORMAT
              7 Microsoft Windows IA (32-bit)                                                                         Little
              6 AIX-Based Systems (64-bit)                                                                            Big
              8 Microsoft Windows IA (64-bit)                                                                         Little
             12 Microsoft Windows x86 64-bit                                                                          LittleHtH
    Johan

  • Can Lincat find big endian and small endian problem?

    Hi, I want to migrate a project from linux to solaris. And I read that lincat can save a lot of time in migration. But when I tried with lincat. I found that what is found is mainly the difference between linux API and solaris API. I use the following
    codes:
    #include <stdio.h>
    #include <stdlib.h>
    int main(int argc, char *argv[])
    int flagVal = 0x01020304;
    char cptr = (char )&flagVal;
    printf("Val is %d\n", *cptr);
    my lincat does not find the big endian and small endian problem. I also wonder whether lincat can find the misaligned problem and "32 bits and 64 bits" problem. Could you please tell me? I didn't find the answer from lincat manual.
    Edited by: baiwd on May 6, 2008 6:03 PM

    Hi Ankit,
    You may use "Cross Platform Transportable Tablespaces" method if the endian format is different between source and target platforms. Please have a look at Oracle's "Platform Migration Using Transportable Tablespaces" document for more information: http://www.oracle.com/au/products/database/maa-wp-11g-platformmigrationtts-129269.pdf
    Please note that "Transportable Database" is a different feature and can only be used to migrate a new database platform that has the same endian format.
    BR,
    Alper Somuncu

  • Big Endian and Little Endian formats.

    How can I read numbers from file in both big and little endian formats?

    Not without reading them a byte at a time and doing
    bit-shifting arithmetic yourself.I was hoping I will not get that kind of answer :) Well, if that's the only way,
    can you tell me what kind of format is used in Java? Big or Little endian?

  • What is Little Endian / Big Endian in Sound settings for Apple Intermediate

    Hi.
    In Final Cut Express, I am trying to splice together multiple video clips, combining footage from:
    1) HDV camcorder imported into iMovie 08 as 960 x 540 (the "lower resolution" option from iMovie '08 import), 16-bit @ 48 KHz (Big Endian), 25 FPS
    2) AVI files (DiVX 512 x 384, MP3 at 44.1 KHz, 23.98 FPS)
    3) Canon Camera "movie" files (Apple OpenDML JPEG 640 x 480, 16-bit Little Endian, Mono @ 44.1 KHz, 30 FPS)
    Questions
    1) What is this little endian / big endian thing?
    2) What is the best codec for me to edit in? My targets are NTSC DVD and also a HD version served via iPod connected to HDTV.
    I am not sure what codec to convert everything to, so that I can edit without having to RENDER every time I do something. I tried to export using QuickTime Pro to convert to Apple Intermediate Codec but am not sure about the option for "Little Endian" (I am using an Intel Mac; I assume I do NOT use little endian? Can someone help clarify?)
    Many thanks!!!

    1. They're compression formats. Different codec use different compression schemes.
    2. You should convert your material to QuickTime using the appropriate DV codec and frame rate.
    None of your material is HD. Some of it is low resolution, lower than even DV. There is no good way to make this material HD.

  • Little endian & big endian format system

    Hi,
    I have code which works fine for Little endian format system, can somebady please tell how to get data from big endian format system.
    or is sap has setting where i can turn on and than run my code on that system.
    Thanks,
    John.

    hi
    chk this
    OPEN DATASET dset IN LEGACY TEXT MODE [(BIG|LITTLE) ENDIAN] [CODE PAGE cp]
    Effect
    Data is read or written in a form which is compatible to BINARY MODE in Releases <= 4.6. This addition is primarily used to convert a file into the code page format specified already when it is opened. At runtime, the system uses the format of the system code page of the application server. The system saves the file then again in the code page specified. This procedure is important if data is exchanged between systems using different code pages. For more information, see READ DATASET and TRANSFER.
    Notes
    on BIG ENDIAN, LITTLE ENDIAN
    These additions specify the byte sequence in which to store numbers (ABAP types I, F, and INT2) in the file.
    These additions may only be used in combination with the additions IN LEGACY BINARY MODE and IN LEGACY TEXT MODE. If these are not specified, the system assumes that the byte sequence determined by the hardware of the application server is used in the file.
    If the byte sequence specified differs from that determined by the hardware of the application server, READDATASET and TRANSFER make the corresponding conversions.
    These additions replace the language element TRANSLATE ... NUMBER FORMAT ... which must not be used in Unicode programs.
    on CODE PAGE cp
    This addition specifies the code page which is used to represent texts in the file.
    This addition may only be used in combination with the additions IN LEGACY BINARY MODE and IN LEGACY TEXT MODE. If this addition is not specified, the system uses the code page defined by the text environment current at the time a READ or TRANSFER command is executed (see SET LOCALE LANGUAGE).
    This addition replaces the language element TRANSLATE ... CODE PAGE ... which must not be used in Unicode programs.
    open datset ... IN LEGACY BINARY MODE [(BIG|LITTLE) ENDIAN] [CODE PAGE cp]
    Effect
    Data is read or written in a form which is compatible to BINARY MODE in Releases <= 4.6. This addition is primarily used to convert a file into the code page format specified already when it is opened. At runtime, the system uses the format of the system code page of the application server. The system saves the file then again in the code page specified. This procedure is important if data is exchanged between systems using different code pages. For more information, see READ DATASET and TRANSFER.

  • Help: Any one can advice, CVI software is using Big or little endian?

    Help: Any one can advice, CVI is using Big or little endian? 
    or is depend on the processors my HW is using?

    The correct answer it the third one: CVI adapts to the hardware architecture you are running on. In the Programmer's Toolbox you have functions to detect the hardware architecture: HostIsBigEndian and HostIsLittleEndian. In the group you have functions to convert data between architectures.
    Proud to use LW/CVI from 3.1 on.
    My contributions to the Developer Zone Community
    If I have helped you, why not giving me a kudos?

  • Big endian - Little endian conversion

    Hi all, I'm a new user!
    I'm working with As400 and java using jtopen.
    With this code:
    PrintObjectTransformedInputStream is = spoolFile.getTransformedInputStream(printParms);           
    BufferedInputStream bufIn = new BufferedInputStream(is);                       
    BufferedOutputStream bufOut = new BufferedOutputStream(new FileOutputStream("c:/x.tif"));
    int c;
    while ((c = bufIn.read()) != -1) {
         bufOut.write(c);
    bufIn.close();
    bufOut.close();I'm getting a tiff stream and then write it to a file. The tiff stream is in Big endian format, but I need a tiff in Little endian format.
    How can I convert the stream from Big endian to Little endian?
    Thanks

    Tiff is a complex format, containing fields of different lengths, so you aren't likely to succeed just by reversing every pair of bytes in the stream without following the TIF format.
    You could look at the JAI (Java Advanced Imaging), which can read and write TIFF files in a variety of modes.

  • Big to Little Endian

    http://download.oracle.com/docs/cd/B14117_01/server.101/b10770/rcmsynta18.htm#87809
    DB Version : 10.1
    We are going across platform, different endianness.
    1. We cannot use CONVERT Database as it is supported only across same platform.
    2. We are planning to use CONVERT Datafile, without transportable tablespace.
    3. Any idea on how much time it would take to copy a 10g File ?
    When there is a endian difference, could you please provide a high level successful methodology to use.
    We are planning to do an OS cold backup, subsequent restore of the entire database on Target, run convert datafile and synchronizing the data from there on. BTw, we are going from Big to Little Endian.
    Can any one provide a estimate on how much time it would take to convert a 10 Gig datafile?
    Also once datafile is converted and brought up, can we apply the archivelog’s I am thinking no, but wanted to know your opinion.
    Edited by: user11986212 on Nov 30, 2009 8:13 PM

    Hi,
    I wrote blog post recently about cross platform migration from big to little endian platform:
    [Cross-platform migration - large Oracle 9i db from Solaris 64 to Linux 64|http://msutic.blogspot.com/2009/11/cross-platform-migration-large-oracle.html]
    First part is upgrade process and you can ignore that part - next is migration across platforms.
    Maybe this post could be helpful for you.
    Regards,
    Marko

  • Little- och big-endian problem?

    Hi!
    I'm writing a program which will run on Windows, Mac OS and Linux. The program will be used for opening binary files created by a program in Windows.
    Because the files are created in Windows i guess they will be created according to the little-endian system. The program that will open them will read them in to the memory as a byte array.
    My question is: will there be a problem to get the right information from these files if I open them on a big-endian system? (There are no magic numbers in the binary file which indicates the used endian system)
    Lina

    I have to admit that I get the meaning of big/little endian confused.
    As JosAH says; Big endian means the big end is first,
    NOT that the big value is at the end.And I have to admit that I find that whole big/little-endian jargon quite confusing
    too, I mean the most significant byte is stored at the lowest address and we
    call it big-endian ... If the number is stored 'backwards' we call it little endian.
    In the old days when computers were made of wood and ran on steam, we
    used to call it 'low-byte-first' and 'high-byte-first'. Sigh ... those were the days ;-)
    kind regards,
    Jos

  • VDI 3.1 Big Endian vs Little Endian: VDI Cluster to Remote mysql server

    Hello,
    We are implementing a Dual Data center VDI environment and with that, will be using VCS to Cluster a remote Mysql instance. My question, if the VDI Cluster is on x86 (Little Endian), can the remote Mysql DB be on Sparc (Big Endian)?
    Thanks,

    The endian matching is only a requirement for the management and data nodes of a MySQL cluster. If you are going to be using a remote MySQL DB, the VDI servers will be connecting to that remote MySQL DB as a client connection, and there is no requirement for clients to match the endian type.
    http://dev.mysql.com/doc/refman/5.1/en/mysql-cluster-limitations-exclusive-to-cluster.html

  • Oracle guids little endian, big endian problem

    hello every one,
    I am having an strange issue. I am developing a .net app against an Oracle DB. Well, when I insert a guid into a raw oracle changes the order of the byte array.
    In VB.net I see (with all the representations of guids, with or without {,- or whatever):
    ac6d5c4f-542e-4fc8-b8b6-f53821811be3
    In Oracle I see (tested with toad and sql tools):
    4F5C6DAC2E54C84FB8B6F53821811BE3
    It goes ok with the rightests numbers but fails the the leftests.
    Any suggestion?

    I have to admit that I get the meaning of big/little endian confused.
    As JosAH says; Big endian means the big end is first,
    NOT that the big value is at the end.And I have to admit that I find that whole big/little-endian jargon quite confusing
    too, I mean the most significant byte is stored at the lowest address and we
    call it big-endian ... If the number is stored 'backwards' we call it little endian.
    In the old days when computers were made of wood and ran on steam, we
    used to call it 'low-byte-first' and 'high-byte-first'. Sigh ... those were the days ;-)
    kind regards,
    Jos

  • What does Little Endian and Floating Point actually do?

    Exporting audio to video using Linear PCM format brings along two mysterios options called "Little Endian" and "Floating Point". I did my research but all I could dig out was that the first one, Little Endian, has to do with addressing subcomponents of a file etc.
    Does anyone know what these two actually mean in terms of exporting audio and why do I only see them in logic and not in Protools for example?
    Thanks...

    Big Endian is most significant byte (bit) first, Little Endian is most significant byte (bit) last. When we write down a number, we use big endian: one million threehundred and twentyfivethousand ninehundred and fiftyfour we'd write as 1 325 954. in little endian notation that would be 459 523 1.
    I don't know why they show up when exporting audio to video, maybe it is to adaprt the audio to some other (older?) formats?

  • How to judge the platform is little or big endian ?

    I have a c code, but anybody has a Java code?
    Thanks.
    #include <stdio.h>
    //little-endian or big-endian
    bool IsLittleEndian()
    int i = 1;
    char* p = (char*)&i;
    return *p;
    int main()
    if(IsLittleEndian())
      printf("LittleEndian\n");
    else
      printf("BigEndian\n");
    return 0;
    }

    http://www.codeproject.com/cpp/endianness.asp
    I got one, but how to translate into Java code.
    Auto detecting the correct Endian format of a data file
    Suppose you are developing a Windows application that imports Nuclear Magnetic Resonance (NMR) spectra. High resolution NMR files are generally recorded in Silicon or Sun Workstations but recently Windows or Linux based spectrometers are emerging as practical substitutes. It turns out that you will need to know in advance the Endian format of the file to parse correctly all the information. Here are some practical guidelines you can follow to decipher the correct Endianness of a data file:
    Typically, the binary file includes a header with the information about the Endian format.
    If the header is not present , you can guess the Endian format if you know the native format of the computer from which the file comes from. For instance, if the file was created in a Sun Workstation, the Endian format will most likely be Big-Endian.
    If none of the above points apply, the Endian format can be determined by trial and error. For example, if after reading the file assuming one format, the spectrum does not make sense, you will know that you have to use the other format.
    If the data points in the file are in floating point format (double), then the _isnan() function can be of some help to determine the Endian format. For example:
    double dValue;
    FILE* fp;
    fread(&nValue, 1, sizeof(double), fp);
    bool bByteSwap = _isnan(dValue) ? true : falseNote that this method does only guarantee that the byte swap operation is required if _isnan() returns a nonzero value (TRUE); if it returns 0 (FALSE), then it is not possible to know the correct Endian format without further information.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   

  • Openfirmware Little + Big Endian

    Hello,
    I was reading a article about OpenFirmware (this one in particlular), and it sayed you can use the command-line tool nvram to look and change the properties of OpenFirmware. When I typed in nvram -p, I got this:
    fcode-debug? false
    skip-netboot? false
    prev-lang:kbd en:0
    load-base 0x800000
    logger-base -1
    default-router-ip
    scroll-lock true
    oem-logo
    boot-screen screen
    default-server-ip
    default-gateway-ip
    security-#badlogins 2
    diag-switch? false
    oem-banner
    default-subnet-mask
    output-device screen
    use-generic? false
    logger-size -1
    diag-file ,diags
    screen-#rows 40
    oem-logo? false
    diag-device enet
    default-client-ip
    default-mac-address? false
    little-endian? false
    aapl,tdm-units
    mouse-device mouse
    input-device keyboard
    virt-base -1
    boot-script
    auto-boot? true
    selftest-#megs 0
    boot-args
    real-base -1
    ram-size 0x20000000
    use-nvramrc? false
    real-size -1
    virt-size -1
    boot-file
    console-screen screen
    boot-volume 3
    input-device-1 /ipc
    real-mode? false
    nvramrc
    gmt-offset 0
    security-mode none
    boot-device pci2/ata-6@D/@0:3,\\:tbxi
    output-device-1 /ipc
    pci-probe-mask -1
    oem-banner? false
    screen-#columns 100
    boot-command mac-boot
    What on earth is little endian doing there? I know that little endian means x86 (Intel, AMD, etc.), and big endian means PowerPC (IBM). What would happen if you turned it to true? This video shows you what little & big endian means. (from Apple) I'm kinda interested in this if x86 was there for years.

    I didn't actually say that there had ever been a little-endian PPC processor, just that Apple have maintained little-endian versions of the OS (and associated parts) and therefore it makes sense that there is some low-level support for controlling the way the system works.
    Just as an aside, the PPC chip has support for both models. According to:
    http://developer.apple.com/documentation/Hardware/DeviceManagers/pcisrvcs/pci_cards_drivers/PCIBOOK.250.html
    The PowerPC microprocessor supports a little-endian processing mode, in which addresses are swizzled when they are used to access memory.
    As that note indicates, it's not a full little-endian support as much as a dynamic flipper that can switch big-endian data into little-endian (and vice versa).

Maybe you are looking for