# How to effectively use bitshift?

Hey there!

I am still noob to programming and was wondering if someone could provide some context on bit-shifting.

In my sketch, I have a buffer which holds 54 characters:

char sampleBuffer[1000];

This is encrypted data which is stored into a buffer.

and I am trying to split the buffer into segments of 6 characters such as:

Taking the above picture as an example:

I'm trying to create code to fill an array "Channel" ( size of 8 ) such as when I call Channel[1] it returns the value "7FFFFF", Channel[2] returns "000000"...

I want to use bitshift to achieve this, but I am having difficulty wrapping my head around it.

I greatly appreciate any help you can provide to point me in the right direction.

There is no obvious reason to use bit shifting.

You forgot to post the code that produces the listing, but at a guess, the first three bytes of "sampleBuffer" contain C00000, the next three bytes contain 7FFFFF, and so on.

PS: it is an incredible waste of memory to declare sampleBuffer to be 1000 bytes, when it should hold 54 characters.

Thanks for your comment. You are in fact correct, there is a total of 27 bytes which makes up 3 bytes status header + 8 channels each 3 bytes.

I want to isolate the status header and split up the 8 channels. I want to experiment with bit-shifting, and wanted to work with the 54 characters as an example.

I'm just looking for a general answer on how it could be done, so I don't necessarily think I need to post any code here.

Also, thank you for pointing out the sampleBuffer memory waste.

I want to experiment with bit-shifting

Start by using your favorite search engine to find tutorials on bit shifting. The keywords "C bit shifting" seem to work.

You seem to be confused about "characters". It takes two ASCII characters in the human readable hexadecimal representation to represent one byte (8 bits) of information. It would be sufficient to declare sampleBuffer to be a character array of length 27, indexed from 0 to 26 (decimal).

``````char x=255; //is binary 0b11111111 or hex 0xFF
``````