4879 views|12 replies

21

Posts

0

Resources
The OP
 

How to concatenate 8 sbits of data into one? Bitwise operation? How to implement it? [Copy link]

 

How to concatenate 8 sbits of data into one data?

For example, the eight bits of data 0, 1, 0, 1, 0, 0, 1, 1 are concatenated into the eight bits of binary data 0101 0011. Can this be achieved through bitwise operations? How?

This post is from 51mcu

Latest reply

The simplest method is to send the content of a bit address to another bit address. This requires that both the source and the destination can be bit-addressed. If the destination unit cannot be bit-addressed, it can only be shifted. sbit can be sent to cy operation   Details Published on 2019-9-15 14:41
 

650

Posts

8

Resources
2
 

a |= b0 << 7;

a |= b1 << 6;

a |= b2 << 5;

a |= b3 << 4;

a |= b4 << 3

a |= b5 << 2;

a |= b6 << 1;

a |= b7 << 0;

This post is from 51mcu

Comments

Thank you! But if b0, b1, etc. are all bit types, there is no way to perform shift operations? ?  Details Published on 2019-8-6 15:50
 
 
 

1w

Posts

142

Resources
3
 

Use the shift left and shift right instructions.

This post is from 51mcu

Comments

It seems that bit data cannot be shifted, an error will be reported!  Details Published on 2019-8-6 15:52
 
Personal signature上传了一些书籍资料,也许有你想要的:http://download.eeworld.com.cn/user/chunyang
 
 

21

Posts

0

Resources
4
 
29447945 Published on 2019-8-6 14:51 a |= b0 << 7; a |= b1 << 6; a |= b2 << 5; a |= b3 << 4; a |= b4 << 3 ...

Thank you! But if b0, b1, etc. are all bit types, there is no way to perform shift operations? ?

This post is from 51mcu

Comments

Type conversion  Details Published on 2019-8-6 15:52
 
 
 

650

Posts

8

Resources
5
 
小99 posted on 2019-8-6 15:50 Thank you! But if b0, b1... these are all bit types, there is no way to perform shift operations? ?

Type conversion

This post is from 51mcu

Comments

Is it to force the bit data to be converted into unsigned char type?  Details Published on 2019-8-6 15:53
 
 
 

21

Posts

0

Resources
6
 
chunyang posted on 2019-8-6 15:21 Use the left and right shift instructions.

It seems that bit data cannot be shifted, an error will be reported!

This post is from 51mcu

Comments

The shift operation is certainly not a bit operation. Is the thinking so linear? The simplest way to do circular shift is to use carry. It is also possible to convert the bit data into byte data and then perform logical operations with the preset variables after shifting, but the execution speed is relatively slow.  Details Published on 2019-8-6 16:29
 
 
 

21

Posts

0

Resources
7
 

Is it to force the bit data to be converted into unsigned char type?

This post is from 51mcu
 
 
 

9702

Posts

24

Resources
8
 
Use union
This post is from 51mcu
 
 
 

1w

Posts

142

Resources
9
 
小99 发表于 2019-8-6 15:52 It seems that bit data cannot be shifted, and an error will be reported!

The shift operation is certainly not a bit operation. Is the thinking so linear? The simplest way to do circular shift is to use carry. It is also possible to convert the bit data into byte data and then perform logical operations with the preset variables after shifting, but the execution speed is relatively slow.

This post is from 51mcu
 
Personal signature上传了一些书籍资料,也许有你想要的:http://download.eeworld.com.cn/user/chunyang
 
 

185

Posts

0

Resources
10
 

Accumulator A is cleared, the bit data is sent to C, and then shifted. After 8 times, there is a byte of data in A.

This post is from 51mcu
 
 
 

1193

Posts

0

Resources
11
 

Doesn't C51 have a bit addressing area? Why not just use it directly?

This post is from 51mcu
 
 
 

291

Posts

0

Resources
12
 

How to achieve it? Can you be more specific?

This post is from 51mcu
 
 
 

4005

Posts

0

Resources
13
 

The simplest method is to send the content of a bit address to another bit address. This requires that both the source and the destination can be bit-addressed. If the destination unit cannot be bit-addressed, it can only be shifted.

sbit can be sent to cy operation

This post is from 51mcu
 
 
 

Guess Your Favourite
Just looking around
Find a datasheet?

EEWorld Datasheet Technical Support

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京B2-20211791 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号
快速回复 返回顶部 Return list