# Mov AL,AH in C++ or C

 Tatrasiel R · April 8, 2015 Lets say I have an integer 20ABHow can I make the integer 2020 by moving the High byte to the Lowbyte place?I am just going through something, but I need a clear way to represent this in C or C++.I was thinking, would this work. Can anyone think of a better way?``int Index 0x000020AB;LOBYTE(Index) = HIBYTE(Index);``

## Replies

 Dol Lod · April 9, 2015 Here is one way to do it if you want  0x00002020``int Index=0x000020AB;Index=(Index>>8); //this gets rid of the AB so you have 0x00000020Index|=(Index<<8); //this keeps the 20 at the end and assigns the previous // two bytes. now index=0x00002020``I hope this is what you were looking for. Just practice shifting. When I first did it, I could not understand a thing. Now I actually am getting how to use left shifting,right shifting,or,and and xor operation. To better understand shifting, I recommend simply using Python's interpreter b/c there is no need to even compile to see how shifting works. M .A.K · April 9, 2015 The above post is the best way possible and it's using pure C/C++;but if u'r just looking for clearest way possible so u should dive in Assembly!so:``#include #include using namespace std;int main() {    register int index asm("ebx");    index = 0x20AB;    __asm__("mov %bh, %bl\n\t");    cout << hex << index;    return 0;}`` Dol Lod · April 9, 2015 @ M.A.K. I don't understand registers and the like that well, but aren't you making an assumption about the OS using Intel x86  instead of something like MIPS or ARM? M .A.K · April 9, 2015 OH ,YIP! I forgot sorry. not only i have that assumption about cpu but also i assume that he/she will use gcc compiler.this program will run on x64_x86 machines. plus other compilers have different ways of assembly integration in a C/C++ code that might not accept gcc way of doing stuff!
• 1

## C++

118,198 followers