Code to concatenate two numbers' bits not working

后端 未结 3 1002
自闭症患者
自闭症患者 2021-01-14 14:16

The task is to concat the binary of 2 given numbers.

Example:

Given 5 (101) and 3 (011),

3条回答
  •  伪装坚强ぢ
    2021-01-14 14:53

    You just shift one number and then or with the other number:

    int a = 5;
    int b = 3;
    int c = (a << 3) | b;
    

提交回复
热议问题