Forum Index > General > Ask an Evil Mad Scientist!
 Hexadecimal calculations in Arduino IDE
 |  Printable Version
By: Leviathan34 (offline) on Sunday, November 22 2009 @ 01:34 PM PST (Read 13753 times)  
Leviathan34

Hey Windell I was wondering how to do hexadecimal calculations in the Arduino IDE (if it's even possible).
Thanks.


Forum Henchperson
Henchperson

Status: offline

Registered: 11/15/09
Posts: 20

Profile Email    
   
By: Windell (offline) on Sunday, November 22 2009 @ 01:47 PM PST  
Windell

Yes, you can use hexadecimal representations of any number in C. See, for example: http://arduino.cc/en/Reference/IntegerConstants


Windell H. Oskay
drwho(at)evilmadscientist.com
http://www.evilmadscientist.com/

Forum Evil Scientist
Evil Scientist

Status: offline

Registered: 06/15/06
Posts: 1932
Sunnyvale, CA

Profile Email Website  
   
By: Leviathan34 (offline) on Sunday, November 22 2009 @ 02:12 PM PST  
Leviathan34

Thanks.

So can I just add, multiply, divide, and subtract the numbers the numbers on their own? Like 0x3B / 0xF


Forum Henchperson
Henchperson

Status: offline

Registered: 11/15/09
Posts: 20

Profile Email    
   
By: Windell (offline) on Sunday, November 22 2009 @ 02:27 PM PST  
Windell

There's no difference to the compiler whether you speak decimal or hexadecimal-- both are foreign languages. It speaks binary.


Windell H. Oskay
drwho(at)evilmadscientist.com
http://www.evilmadscientist.com/

Forum Evil Scientist
Evil Scientist

Status: offline

Registered: 06/15/06
Posts: 1932
Sunnyvale, CA

Profile Email Website  
   
By: Leviathan34 (offline) on Sunday, November 22 2009 @ 05:58 PM PST  
Leviathan34

Okay, now would I be correct in saying that you can only store hexadecimal in a byte variable?

Also I tried to divide a byte variable by a byte variable and it said something along the lines of error using type byte[1] [1] and byte[1] [1] with operator /.


Forum Henchperson
Henchperson

Status: offline

Registered: 11/15/09
Posts: 20

Profile Email    
   
By: karlgg (offline) on Tuesday, December 01 2009 @ 10:31 AM PST  
karlgg

Hexadecimal is like decimal, it's just a different representation of numbers... It just happens to "fit" with binary better, as 16 is a power of 2 (which also makes it easier to visualize the individual bits, once you're familiar with it). There's no "size limit" to hexadecimal, any more than there is a limit to decimal.

A byte (8 bits) could be shown as 255 in decimal, or FF in hexadecimal (or 11111111 in binary). If you have a bigger number, it takes more digits, just like you'd expect. 16 bits would use four hexadecimal digits instead of two.


I think I am, therefore I am... I think
Forum Mad Scientist
Mad Scientist

Status: offline

Registered: 01/25/09
Posts: 81

Profile Email    
   



 All times are PDT. The time is now 04:41 PM.
Normal Topic Normal Topic
Locked Topic Locked Topic
Sticky Topic Sticky Topic
New Post New Post
Sticky Topic W/ New Post Sticky Topic W/ New Post
Locked Topic W/ New Post Locked Topic W/ New Post
View Anonymous Posts 
Able to Post 
Filtered HTML Allowed 
Censored Content 

Evil Mad Scientist Forum Archives — Read only!

Please visit our new forums for new discussions.


DIY Hardware for Electronic Art


The Original Egg-Bot Kit


Octolively
Interactive LED kits


Meggy Jr RGB
LED matrix game
development kit.


Business-card sized
AVR target boards


Peggy 2
LED Pegboard kits

My Account






Lost your password?