Solved

high-Low-Bit Shifting

Posted on 2003-12-11
5
388 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
  • 3
  • 2
5 Comments
 
LVL 45

Accepted Solution

by:
sunnycoder earned 100 total points
Comment Utility
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
Comment Utility
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
Comment Utility
>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
Comment Utility
LOL ... looks like I copied too much from the post

I am becoming absent minded :o(
0
 
LVL 15

Expert Comment

by:jimmack
Comment Utility
;-)
0

Featured Post

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

Suggested Solutions

Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
Although it can be difficult to imagine, someday your child will have a career of his or her own. He or she will likely start a family, buy a home and start having their own children. So, while being a kid is still extremely important, it’s also …
In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

743 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now