## Comparing unsigned char bits.

Comparing unsigned char bits.
# 1
04-15-2012
Comparing unsigned char bits.

The output here is not what I am expecting. I want the input to be displayed in binary.
 robin_simple View Public Profile for robin_simple Find all posts by robin_simple
# 2
04-15-2012
What exactly is not what you are expecting ? Your program output is displayed in binary and the values looks correct to me.

There are minor things that can be improved, like:
• computing sizeof(unsigned char) which is pointless as it is always 1 by the standard.
• printf("%c\n",display_mask); doesn't print anything useful as ASCII character 128 is non printable.
• printf ( "%7c = ", value ); %7c should be just %c as you aren't using wide (multibyte) characters.
 jlliagre View Public Profile for jlliagre Find all posts by jlliagre
# 3
04-15-2012
If I enter 9, the output is

Enter an unsigned character: 9
?
9 = 00111001

So, the question mark is because 128 is too big for 1 byte and I am not expecting 00111001 because that is 2^5 + 2^4 + 2^3 + 1.
 robin_simple View Public Profile for robin_simple Find all posts by robin_simple
# 4
04-15-2012
Quote:
Originally Posted by robin_simple
So, the question mark is because 128 is too big for 1 byte
No, bytes are from 0 to 255. The question mark is there because ASCII character 128 is non printable.
Quote:
and I am not expecting 00111001 because that is 2^5 + 2^4 + 2^3 + 1.
Well, 00111001 is precisely the binary representation of the '9' character. What are you expecting instead ?
 jlliagre View Public Profile for jlliagre Find all posts by jlliagre
# 5
04-15-2012
00001001

---------- Post updated at 03:34 PM ---------- Previous update was at 03:30 PM ----------

How could I translate each binary position in an unsigned char to a corresponding number 1 - 8?
 robin_simple View Public Profile for robin_simple Find all posts by robin_simple
# 6
04-15-2012
Numbers already are bits, so you can just use the bit shift operator.

And do binary math to see when they're set.

 Corona688 View Public Profile for Corona688 Visit Corona688's homepage! Find all posts by Corona688
# 7
04-15-2012
Quote:
Originally Posted by robin_simple
00001001
Then read the "9" as a number instead of as a character...
Or read it as a char and extract out the the number by subtracting '0' from it...
 shamrock View Public Profile for shamrock Find all posts by shamrock

## Unsigned to signed, error?...

Hi guys... Macbook Pro, 13", circa August 2012, OSX 10.7.5, default bash terminal. I require the capability to convert +32767 to -32768 into signed hex words... The example piece code below works perfectly except... #/bin/bash # sign.sh # Unsign to sign... while true do # I have used...

## Place Bits & Win Bits!!! - 17th Annual Satellite Awards

Ten movies have been nominated as best motion picture by the International Press Academy, presentation of the 2012 Satellite Awards will be held on 16th December at Los Angeles, CA. Place your bits here on one of the below nominated movie of your choice:- Argo ...

## Signed and unsigned intergers

when a date type is considered signed and unsigned is that simple referring to - for signed and positive numbers for unsigned? Further if that is the case would mutiplying and dividing ect where 2 signed numbers, like (-2)*(-2) = 4 result in a unsigned.

## Help with understanding ( int, char, long, short, signed, unsigned etc.... )

My question is simple: When should I use a long, int, char, unsigned/signed variables?? When I declare a variable "unsigned;" what did I do it??? Why would I delcare an integer "long" or "short" ( unsigned or signed)?? Any examples of when things like "unsigned", "long", "short" etc......

## 32 bits procesaor with 64 bits Solaris

people i have a problem i have a 32 bits sparc processor, and solaris 64 bits processor, i install a oracle data base 64 bits, but my oracle will not run because my processor is from 32 bits this is ok??, i know if i have x86 i cannot install a 64 bits operatin system in a 32 bits processor. ...

## to get the correct value with unsigned int

hi, Please help me with the following code to get the difference in values. struct a{ int b1; int c1; char d1; } main() { unsigned int b=10; unsigned int c; c = b - (unsigned int )sizeof(a); printf("%d",c); } Here c returns some junk value. How can i get the...

## Changing 24 bits to 8 bits display

Hello all, I was wondering if anyone can tell me how to change 24 bits depth display to 8 bits depth display for Sun Ultra1, running Solaris 8? THANKS in advance. I think that the command is ffbconfig, but it has nothing about depth.

## Unsigned int

How can I store and/or print() a number that is larger than 4 294 967 295 in C? is int64_t or u_int64_t what I need ? if, so how can I printf it to stdout?