Go Down

Topic: wrong answer when makin hex --> binary conversion. (Read 764 times) previous topic - next topic

duality

Hello,
i was wondering if someone could help me out :)

so i was experimenting with conversion of value's

i tried to turn 5FFF hex into a binairy number that gave me 100011001000110

to see if this was right i put 5FFF in a online hex to binary converter and that gave me:
0101111111111111

this one must be right since i need 16 bits for my project.

ow and when i tried to make a hex from that binary number it gave me 3130

so the serial monitor can't display letters or?

i am not new to the arduino, i am no pro either so just learning :)

any help would be appreciated,
and thanks in advance ! :)

Code: [Select]


void setup() {
 // put your setup code here, to run once:

 
 Serial.begin(9600);
 Serial.println('5FFF', BIN);
 delay(1000);
 Serial.println(100011001000110, HEX);

}

void loop() {
 // put your main code here, to run repeatedly:
 
}
http://www.youtube.com/user/Shockszzbyyous
my website: freeduality.tk

AWOL

#1
Aug 11, 2011, 10:40 pm Last Edit: Aug 11, 2011, 10:46 pm by AWOL Reason: 1
Quote
Serial.println('5FFF', BIN);
 delay(1000);
 Serial.println(100011001000110, HEX);


The first print has a multichacter constant as parameter (not a string), the second has a large decimal number as parameter.
What did you intend?

0x5FFF is the normal way of writing a hex constant. No quotes.
0b100011001000110 is one way of writing a binary constant.

0100 is an octal constant.
"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

Grumpy_Mike

Why do you want to convert them? They are stored as a bit pattern and it is only when you want to print it out do you need to specify a pretty format. And the print statement will do that for you.
Serial.Print(0x5FFF, BIN);
Will print out the hex value of 5FFF in binary.

duality

yes i see thank you guys i didn't know that :P i learned something now.
i tried to look it up but could really find any answers,

was just experimenting away with the serial monitor and how to change the notation of a value.
experimenting give's me new idea's for project's anyways :P
http://www.youtube.com/user/Shockszzbyyous
my website: freeduality.tk

James C4S

Quote
experimenting give's me new idea's for project's

You are aware that in English when you make a word plural, it is not necessary (or correct) to use an apostrophe?  The apostrophe generally indicates ownership, not plurality.

Capacitor Expert By Day, Enginerd by night.  ||  Personal Blog: www.baldengineer.com  || Electronics Tutorials for Beginners:  www.addohms.com

AWOL

Quote
The apostrophe generally indicates ownership, not plurality.

...and also elision (e.g. "isn't" == "is not")
"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

duality

i know i use that ' to much,
you can understand what i'm saying right? :P
http://www.youtube.com/user/Shockszzbyyous
my website: freeduality.tk

Grumpy_Mike

Yes but it makes you seem less intelligent that you probably are.

Go Up
 


Please enter a valid email to subscribe

Confirm your email address

We need to confirm your email address.
To complete the subscription, please click the link in the email we just sent you.

Thank you for subscribing!

Arduino
via Egeo 16
Torino, 10131
Italy