Solved

high-Low-Bit Shifting

Posted on 2003-12-11
5
396 Views
Last Modified: 2010-05-18
Hi,

I have 3 bytes, a,b and c.

a= byte 1: contains high 8 bits of a
b= byte 2: contains high 8 bits of b
c= byte 3: contains 4 bits low(for byte 1) and 4bits low (for byte 2)

i want to take the first 4 bits of c and insert them in the low of a .So result should be

a= {lo 4 bits  of c}{high 8 bits of a} = 12 bits;

thanks
0
Comment
Question by:XPUSR
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
5 Comments
 
LVL 45

Accepted Solution

by:
sunnycoder earned 100 total points
ID: 9919750
Hi XPUSR,

lo 4 bits of c
c & 0x15

a anyway has 8 bits
a= {lo 4 bits  of c}{high 8 bits of a}

((c & 0x15 ) <<8) | a

to get

Cheers!
Sunny:o)
0
 
LVL 15

Assisted Solution

by:jimmack
jimmack earned 25 total points
ID: 9921088
Sunny, I confess that I don't know which language this is, but doesn't 0x usually precede a hexadecimal value?

So you meant 15 decimal or 0x0F

?

Just checking ;-)
0
 
LVL 45

Expert Comment

by:sunnycoder
ID: 9925928
>but doesn't 0x usually precede a hexadecimal value?

>So you meant 15 decimal or 0x0F
yes ... you are right :o)

May be I was in too much hurry when I typed the response

modified response

 Comment from sunnycoder
Date: 12/11/2003 06:11PM IST
 Your Comment  

Hi XPUSR,

lo 4 bits of c
c & 0x0F

a anyway has 8 bits
a= {lo 4 bits  of c}{high 8 bits of a}

((c & 0x0F ) <<8) | a
 
 thanks jimmack
0
 
LVL 45

Expert Comment

by:sunnycoder
ID: 9925934
LOL ... looks like I copied too much from the post

I am becoming absent minded :o(
0
 
LVL 15

Expert Comment

by:jimmack
ID: 9927510
;-)
0

Featured Post

Enroll in May's Course of the Month

May’s Course of the Month is now available! Experts Exchange’s Premium Members and Team Accounts have access to a complimentary course each month as part of their membership—an extra way to increase training and boost professional development.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Does the idea of dealing with bits scare or confuse you? Does it seem like a waste of time in an age where we all have terabytes of storage? If so, you're missing out on one of the core tools in every professional programmer's toolbox. Learn how to …
Displaying an arrayList in a listView using the default adapter is rarely the best solution. To get full control of your display data, and to be able to refresh it after editing, requires the use of a custom adapter.

734 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question