目录

Is the HarmonyOS NEXT system in big-endian or little-endian mode?

It is in little-endian mode. You can verify the mode using the following code:

@Entry
@Component
struct IndexTest {
  @State message: string = 'Hello World';

  isLittleEndian(): boolean {
    const buffer = new ArrayBuffer(2);
    const uint8Array = new Uint8Array(buffer);
    const uint16Array = new Uint16Array(buffer);
    // Write 0xAA and 0xBB into the buffer
    uint8Array[0] = 0xAA;
    uint8Array[1] = 0xBB;
    // If read in small order, 0xBBAA will be interpreted as 48042
    // If read in big endian order, 0xAABB will be interpreted as 43707
    return uint16Array[0] === 0xBBAA;
  }


  aboutToAppear() {
    if (this.isLittleEndian()) {
      console.log('Small end');
    } else {
      console.log('Big end');
    }
  }


  build() {
    RelativeContainer() {
      Text(this.message)
        .id('IndexTest')
        .fontSize(50)
        .fontWeight(FontWeight.Bold)
        .alignRules({
          center: { anchor: '__container__', align: VerticalAlign.Center },
          middle: { anchor: '__container__', align: HorizontalAlign.Center }
        })
    }
    .height('100%')
    .width('100%')
  }
}