1. Write a function or macro, which takes three values between 0 and 31, and converts this to BGR 16 bit format. For example, the function prototype should look like u16 BGR(u16 b, u16 g, u16 r);
That's the assigment from my teacher, but i think in 'normal' terms that means:
Write a function that takes RGB(r,g,b); r, g and b being values between 0 and 31; it then converts it to 16 bit RGB.
I haven't a clue how to do that, or what it means.
Thanks in advance.
16 4334
That's the assigment from my teacher, but i think in 'normal' terms that means:
Write a function that takes RGB(r,g,b); r, g and b being values between 0 and 31; it then converts it to 16 bit RGB.
I haven't a clue how to do that, or what it means.
Thanks in advance.
Note that a value in the range [0, 31] takes up 5 bits. Three of them next to each
other take up 15 bits. That fits nicely in a 16 bit word. Have a look at the bit shift
operators << and >>
kind regards,
Jos
Note that a value in the range [0, 31] takes up 5 bits. Three of them next to each
other take up 15 bits. That fits nicely in a 16 bit word. Have a look at the bit shift
operators << and >>
kind regards,
Jos
That doesn't really mean much to me. I haven't done much with bits, bit shift etc..
That doesn't really mean much to me. I haven't done much with bits, bit shift etc..
Well: start reading then.
kind regards,
Jos
Well: start reading then.
kind regards,
Jos
It would help if you could sort of lead me in the right direction.
It would help if you could sort of lead me in the right direction.
That was exactly what I was doing: you have to solve the problem how to fit
three 5 bit numbers in one 16 bit number (there'll be one bit left then).
kind regards,
Jos
That was exactly what I was doing: you have to solve the problem how to fit
three 5 bit numbers in one 16 bit number (there'll be one bit left then).
kind regards,
Jos
Thanks, but i know what i have to do. The question was and still is, how do i do it?
Thanks, but i know what i have to do. The question was and still is, how do i do it?
Well I gave you a hint already: read about the bit shift operators << and >>
but you simply said you know nothing about them, on which I replied that you
should read up on them. You don't want to keep this going on ad nauseam do you?
kind regards,
Jos
Well I gave you a hint already: read about the bit shift operators << and >>
but you simply said you know nothing about them, on which I replied that you
should read up on them. You don't want to keep this going on ad nauseam do you?
kind regards,
Jos
So basically:
Shifting left using << causes 0's to be shifted from the least significant end (the right side), and causes bits to fall off from the most significant end (the left side). This occurs whether the variable is signed or unsigned.
Shifting left by K bits is equivalent to multiplying by 2^K.
Shifting right using >> causes 0's to be shifted from the most significant end (the left side), and causes bits to fall off from the least significant end (the right side) if the number is unsigned. If it's signed, then it's implementation depedendent. It may shift in the sign bit from the left, or it may shift in 0's (it makes more sense to shift in the sign bit).
For unsigned int, and sometimes for signed int, shifting right by K bits is equivalent to dividing by 2^K (using integer division).
Bitshifting doesn't change the value of the variable being shifted. Instead, a temporary value is created with the bitshifted result.
So basically i have to change 31 into a 5 bit number? This is really confusing me.
HI...
look 31 is basically 5 bits in memory, you was defined R,G, and B as integer thats mean each one holds in 16 bits,you must take only 5 bits fom each 16 and then merge '3 5bits in one integer variable
GOOD LUCK
So basically:
So basically i have to change 31 into a 5 bit number? This is really confusing me.
You do realize that any value in the range [0,31] takes up only 5 bits do you?
kind regards,
Jos
You should let us know if you are having trouble understanding the fundamental concept of numbers and their representation as bits. If the idea that a number from 0-31 takes only 5 bits is not instantaneously intuitive, then ask us why.
The syntax for this problem is very easy. You only need to know about bit shifts. The concepts are also easy, but if you don't understand the concept, you can't write the few lines of code.
How a simple problem can become a complicated educational issue. If only the OP
would come back so this entire little thingy could be solved in a nice way.
kind regards,
Jos
How a simple problem can become a complicated educational issue. If only the OP
would come back so this entire little thingy could be solved in a nice way.
kind regards,
Jos
I don't understand anything about bits really.
Why can't you just post the solution, with annotations so i understand what it does? Then we'd all be happy.
I don't understand anything about bits really.
Why can't you just post the solution, with annotations so i understand what it does? Then we'd all be happy.
No we won't:
1) you still won't understand;
2) if you'd turn our work in you'd be cheating;
3) we don't cooperate with cheating;
4) future coworkers won't like you as a cheater;
5) at the end you won't be happy either.
Read up on those simple bit shifting operators and don't try to cheat.
kind regards,
Jos
No we won't:
1) you still won't understand;
2) if you'd turn our work in you'd be cheating;
3) we don't cooperate with cheating;
4) future coworkers won't like you as a cheater;
5) at the end you won't be happy either.
Read up on those simple bit shifting operators and don't try to cheat.
kind regards,
Jos
I have read up on them, but they don't seem so simple. Maybe you could explain them, if you don't think i'll understand...
All you have to do is explain to me this bit shifting and bits in general. Then how i would use it for the concept of RGB.
But no.
I have read up on them, but they don't seem so simple. Maybe you could explain them, if you don't think i'll understand...
But if you don't understand the material you find in your book or with Google, then you won't understand our explanations either. If there's a concept you don't understand, something about the material you don't get, you need to tell us what it is you don't understand.
All you have to do is explain to me this bit shifting and bits in general. Then how i would use it for the concept of RGB.
The concept can be explained with a Google search. You complain you don't understand the material. How do we know our explanation won't be wasted on you?
Moreoever, figuring out how to use bit shifting for RGB is the homework assignment. You need to think about it. As far as we can tell, you just want the answer, and you'll take the explanation if you feel like it.
I'll give you a short description of bits and bit shifting. Let's see if you go anywhere with this.
A bit can be thought of as an on/off switch, because that's effectively what it is in hardware. Let's call off 0 and on 1. These would be your binary digits. When it comes to numbers, bits can correspond perfectly with a binary number. Let's say you have two bits. You can have this. -
Bit 1 Bit 0 Binary Number Decimal Number
-
0 0 00 0
-
0 1 01 1
-
1 0 10 2
-
1 1 11 3
-
Can you see a pattern with how many bits you need to have how large a number? R, G, and B go from 0 to 31. How many bits do they need minimum?
Now consider bit shift. As it sounds, it's simply a shift:
0010 << 1 becomes 0100
0001 << 3 becomes 1000
It's the reverse direction for >>.
Now think. Knowing how many bits there are in R, G, and B, and using bit shifting, how can you form a 16 bit "number" from R,G, and B?
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Muffinman |
last post by:
Hi,
I'm trying to build a script which will fade the colour of my text to
another. Now I've got here a litte problem. Whene ever I want to replace
one of the numbers in:...
|
by: Adam Teasdale Hartshorne |
last post by:
I need to convert a colour defined as floats of R,G and B channels into
the same R,G and B channels but defined by unsigned char's. Any help?
Adam
|
by: Steven |
last post by:
Can anyone direct me to a colour picker of the same (or similar quality) to
the default .NET one but one that encompasses ability to specify colour by
HEX value?
|
by: Anonieko Ramos |
last post by:
Answer:
http://weblogs.asp.net/tims/archive/2004/04/02/106310.aspx
by Tim Sneath
I've come across the situation on a number of occasions when coding
where I've wanted to convert from a string...
|
by: Supra |
last post by:
value of type "Integer" cannot be convert to system.color
Public Sub APIHighlight2(ByVal BgColour As Integer, ByVal FgColour As
Integer)
SelectionHighlightBackColour(BgColour)
Dim rtb As New...
|
by: tinab |
last post by:
I have all my data in an excell sheet and I what to transfer it to ACAD.
I need a function, macro that extracts the colour of a cell in excel and gives me back three RGB values in another cell. I...
|
by: JJ |
last post by:
I have a function that returns an int that represents an rgb colour code
(e.g. '5731173').
How can I convert this to a hex value of the form #D2D2D2 so that I can use
it to color an object?
...
|
by: Robbie |
last post by:
Hi. I've made 2 functions which play around with colours.
They convert a 'colour number' (I don't know what the proper name for it is, so I call it this - the Long given back by RGB(),...
|
by: beertje |
last post by:
This has me a bit stumped...
I'm trying to extract pictures from a file. So far I'm successfully
retrieved the header and what I think is the colour for each pixel.
Here's the description:
...
|
by: Arun |
last post by:
I came across a message sometime back in 2002. Here's a link:...
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
| | |